Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Can you create *real* global variables?

by Dominus (Parson)
on Jan 26, 2002 at 20:42 UTC ( #141789=note: print w/ replies, xml ) Need Help??


in reply to Re: Can you create *real* global variables?
in thread Can you create *real* global variables?

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.

--
Mark Dominus
Perl Paraphernalia


Comment on Re: Can you create *real* global variables?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://141789]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2014-07-26 12:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (176 votes), past polls