in reply to Avoiding Global Vars
Seriously, what global $vrx?
First, it's "my". It's lexical. So, perhaps it's lexical to the whole file, but that's not the same as global. Not entirely.
Second, your example code is merely a long version of a one-liner. I realise you're trying to simplify to show your point, but I'm not sure where the point is. If it's something to do with a simple script that doesn't even have need of sub's, then I think you're missing the point of the "GLOBALS ARE EV1L!!!!111" camp. The point of this camp is that action-at-a-distance is unmaintainable. And I agree. Your $vrx variable has no significant distance. It covers 4 lines, that's a very narrow scope for a variable.
Third, as a one-liner, your example could be rewritten just slightly to put all your code into a sub main { ... }, and then a single call to main() would call it, without any functional or even semantic change. Since this is perl, and TMTOWTDI applies, we just ignore the main() routine that other languages force on you, and allow you to just put it all out in the open. That doesn't make your variables global.
What makes a variable global is the intention for, and actual use of, given variables in various scopes. That is, if you have $vrx and it's used by sub foo, and sub bar, then it's an evil global variable. Your example doesn't show that.
Your anal retentiveness is fine. It's just not anal enough: you're applying it to anything and everything, instead of anally selecting which variables are actually global. :-P
|
|---|