The problem seems vaguely related to another for loop behaviour that I think is unintuative and could be construed as a bug.
Sometimes you need to know what value a loop counter had when the loop exited early. If you use my on the loop counter, then it has gone out of scope when the loop exits and this information is lost.
The apparently obvious thing to do is to declare the loop counter before the loop so that it still exists afterwards, but this doesn't work:
#! perl -slw use strict; my $i = 123; for $i ( 0 .. 10 ) { last if $i == 5; } print $i; __END__ 123
Even though the strict is enabled, no warning is issued, which means the $i used by the for loop can only be the lexical declared above it. But still the value of $i after the loop is the value set preceding it. The only way to view this is that $i has been localised for the duration of the loop; but you (the programmer) cannot use local on a lexical.
It is probably a side-effect of making $i an alias for to the values it takes on for the duration of the loop, but it is unintuative and darned annoying.
In reply to Re: Deparse broken or just misunderstood?
by BrowserUk
in thread Deparse broken or just misunderstood?
by Roy Johnson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |