in reply to Re: (tye)Re: How to set a set of our and @EXPORT variables concisely?
in thread How to set a set of our and @EXPORT variables concisely?
But as you found out, the our declares a global variable but the lexical alias to it goes away when you leave the enclosing scope (either the eval or the BEGIN, I'm not absolutely sure which and it would be hard to test but it doesn't really matter here).
So you still have to fully qualify the variable name in the rest of your script. As I already said, there is no good fix for this other than use vars.
I see no mention of use vars being depricated. The closest thing I found was "NOTE: The functionality provided by this pragma has been superseded by `our' declarations". Since using our makes your script not work on even very slightly old versions of Perl, there will still be many scripts using use vars for quite a long time. So deleting vars.pm would be quite stupid of the perl porters, especially since it would be impossible to write version-portable code via something like:
for the exact same reasons that our doesn't work for your code.BEGIN { if( 5.6 < $^V ) { eval 'our $x; 1' or die $@; } else { require vars; vars->import( '$x' ); } }
So don't worry about vars.pm going away until you actually read that is has been deprecated (not "superseded").
Note that our makes for slightly more efficient code, and this is probably why the use vars documentation points you in that direction a little strongly. This efficiency is pretty trivial so I wouldn't sacrifice maintainability (by having two lists of variables to keep in sync) for it.
- tye (but my friends call me "Tye")
|
|---|