in reply to when is "my" not necessary?
In addition to what runig said, note that Perl has two places to store variables. The first is the lexical scope pad. That's where my variables go. Lexical scopes can be created and destroyed by a lot of things, but the most common is within blocks:
my $n = 1; { my $n = 2; print $n; # Prints 2 } print $n; # Prints 1
The second place is the symbol table. This is where variables declared our and local go (among other things). The symbol table can be accessed directly from Perl code (you need a C-based backend to play with the lexical pad directly).
Using lexicals is usually the Right Thing.
"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: when is "my" not necessary?
by Mutant (Priest) on Nov 02, 2004 at 20:57 UTC | |
by hardburn (Abbot) on Nov 02, 2004 at 21:00 UTC | |
by Ven'Tatsu (Deacon) on Nov 02, 2004 at 21:15 UTC | |
by hardburn (Abbot) on Nov 02, 2004 at 21:17 UTC |