in reply to what is the scope of my $x=$x
What happened when you tried it out?
There are two variables called $x there. The one on the left hand side of the assignment is a lexical variable and it will be in scope from this statement until the end of the innermost enclosing block. On the right hand side of the assignment is a existing package variable and its scope depends on where and how you created it. By default its scope will be the whole of the package that it was created in.
Try experimenting with this code:
$x = "foo"; print "$x / $main::x\n"; { my $x = $x; print "$x / $main::x\n"; $x = "bar"; print "$x / $main::x\n"; } print "$x / $main::x\n";
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: what is the scope of my $x=$x
by Hue-Bond (Priest) on Jun 25, 2006 at 01:55 UTC |