|
|
| Do you know where your variables are? | |
| PerlMonks |
Re^3: style guidanceby ikegami (Patriarch) |
| on Nov 09, 2009 at 19:57 UTC ( [id://806001]=note: print w/replies, xml ) | Need Help?? |
|
& is not a no-op. It causes prototypes to be ignored.
my should be used whenever possible, but it's not possible to use my on package variables.
$_ was made a legal name for a lexical in 5.10, and builtins will use the lexical $_ instead of the global $_ if there is one in scope, but not everyone is using 5.10 yet.
One reason my is preferred over local is that my creates a new variable, whereas local simply saves the variables current value (and restores it on scope exit). Any magic associated with the variable is unaffected by local. You can localise the variable rather than its value by localising the glob that contains the variable. A glob is an associative array (like a hash) that contains the different type of variables ($name, @name, %name) associated with each name in the symbol table. local *_ localises the whole glob, which means a new $_ will be created if one is needed.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||