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

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?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2016-10-23 17:34 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (301 votes). Check out past polls.