in reply to Re: Scope and references
in thread Scope and references
Thanks. But that's what I don't get. Here's my confusion. I never realized that a simple loop like this (an even simpler illustration this time) ...
for (my $i=0; $i <=1; $i++){ my @a; $a[$i] = 99; print Dumper(\@a); }
... which results in ...
$VAR1 = [
99
];
$VAR1 = [
undef,
99
];
...actually allocated and destroyed a new array every time through the loop. Since you go around the loop twice, it seems like you don't "leave" the scope in which @a was delcared, so @a should still "be there" during the second iteration. I still don't get that.
Also, I still don't understand why the 'wrong' version creates the data structure that it does. Any thoughts on that one?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Scope and references
by BrowserUk (Patriarch) on Jun 19, 2011 at 17:41 UTC | |
by {}think (Sexton) on Jun 19, 2011 at 18:44 UTC | |
by {}think (Sexton) on Jun 22, 2011 at 02:33 UTC | |
by Anonymous Monk on Jun 23, 2011 at 13:05 UTC | |
|
Re^3: Scope and references
by ikegami (Patriarch) on Jun 19, 2011 at 19:35 UTC | |
by 7stud (Deacon) on Jun 20, 2011 at 08:01 UTC | |
by ikegami (Patriarch) on Jun 20, 2011 at 17:03 UTC | |
|
Re^3: Scope and references
by jpl (Monk) on Jun 19, 2011 at 18:31 UTC | |
by jpl (Monk) on Jun 20, 2011 at 10:51 UTC |