Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Can you create *real* global variables?by Dominus (Parson) |
on Jan 26, 2002 at 20:42 UTC ( [id://141789]=note: print w/replies, xml ) | Need Help?? |
Said robin:
Something that hasn't being mentioned is that all punctuation variables are always global, even if they aren't magical.I did say this.
The situation with ${^Name} variables is a little more complicated: the fact is that any variable name that starts with a punctuation character is implicitly global, but the Perl parser only recognises single punctuation characters.The actual rule is that any name that starts with a character other than a letter or underscore is global. (Unless your source code is written in unicode, in which case i don't know what happens.) So in particular, $0 and $1 are global. Variables like ${^Name} don't start with punctuation either: As robin said, this one appears to start with ^, but actually it starts with the control-N character. Since control-N isn't a letter or underscore, ${^Name} is global.
There's one exception to that: you can also use :: as a name, so you can use the variable $:: which is of course global.Not so. $:: is actually the same variable as $main::main::. (Thanks to Abigail for tracking this down.) There's a special case in gv.c that treats an empty package name as main, and it gets invoked twice here.
--
In Section
Seekers of Perl Wisdom
|
|