You did the "right thing" only if you don't need to keep data globally or you will be forced to run some sub/function otherwise.
Wich way works better for you - you are the one to determine.
There isn't right or wrong - it's what's necessary that matters. And what language someone is using is quite irreelvant in this case - concept is the same.

Best regards.