Perl: the Markov chain saw | |
PerlMonks |
Re: to "use vars" or not toby 7stud (Deacon) |
on Nov 08, 2010 at 21:51 UTC ( [id://870204]=note: print w/replies, xml ) | Need Help?? |
Declaring global variables using fully qualified names:
Above okay under use strict. Declaring global variables with use vars:
'use vars' provides a shortcut: you don't need to use the fully qualified variable name, which is what use strict requires. Declaring global variables with our:
Once again, our provides a shortcut to having to use fully qualified names under use strict. What's the difference between our and use vars?
'use vars' has file scope, i.e. it applies to the whole file, and cannot be undone (e.g. with 'no use vars')--while our has block scope, so the short form of the variable name only works within the same block as the our statement.
Note that the global variable always exists no matter what method you use--the issue is whether you can refer to the global variable using the short form of the variable name or not.
In Section
Seekers of Perl Wisdom
|
|