in reply to redeclaring variables with 'my'
Now, I'm no expert on Perl internals, but it certainly seems like $x is being re-allocated for every loop. At a minimum, $x falls out of scope when the loop ends, which leads me to believe it's falling out of scope for each iteration and being re-allocated. Note that it isn't being redeclared, just reallocated. I'd be interested if anyone has any other explanation...# within while (my $x = $count) { $count++; last if $count >= 5000000; } # without my $x; while ($x = $count) { $count++; last if $count >= 5000000; } Benchmark: timing 10 iterations of within, without... within: 40 wallclock secs (39.78 usr + 0.04 sys = 39.82 CPU) @ 0 +.25/s (n=10) without: 35 wallclock secs (35.09 usr + 0.00 sys = 35.09 CPU) @ 0 +.28/s (n=10)
|
---|
Replies are listed 'Best First'. | |
---|---|
RE (tilly) 2: redeclaring variables with 'my'
by tilly (Archbishop) on Nov 11, 2000 at 02:30 UTC | |
by Fastolfe (Vicar) on Nov 11, 2000 at 02:38 UTC | |
RE: Re: redeclaring variables with 'my'
by btrott (Parson) on Nov 11, 2000 at 02:35 UTC | |
by Fastolfe (Vicar) on Nov 11, 2000 at 02:39 UTC | |
by tilly (Archbishop) on Nov 11, 2000 at 03:04 UTC | |
by Fastolfe (Vicar) on Nov 11, 2000 at 03:07 UTC | |
RE: Re: redeclaring variables with 'my'
by extremely (Priest) on Nov 11, 2000 at 03:16 UTC |