in reply to Re^7: no chunk is too small
in thread Last undefines a for loop's itererator?
I would not change any other constructs, nor the way $_ is localised.
I would prefer it if this
my $i; for $i ( 0 .. 10 ) { last if <somecondition>; ... } my $x = substr $somestring, 0, $i;
was consistant with
my $i=0; { ... last if <somecondition>; $i++; redo; } my $x = substr $somestring, 0, $i;
or
$i=0; do{ ... $i++ } until <somecondition>; my $x = substr $somestring, 0, $i;
If you stop getting hung up on the magic of $_, which I wouldn't change anyway, I think that lexicals that automagically revert to some previous value after the programmer has explicitly modified that value is a mysterious and non-useful behaviour that definitely doesn't DWIM.
If the programmer wants that behaviour, he could still get it by using nested scopes to achieve it
my $i=42; for my $i (1..10){ print $i; } print $i; ## gives 1 2 3 4 5 6 7 8 9 10 42
As is, the current behaviour is a special case (of a pre-existing lexical that gets automagically localised), that doesn't fit the pattern of other looping constructs (map & grep can't use lexicals as their iterator variables) and a special case that removes flexibility, adds nothing and is confusingly non-useful.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: no chunk is too small
by Aristotle (Chancellor) on Nov 14, 2005 at 02:35 UTC | |
by BrowserUk (Patriarch) on Nov 14, 2005 at 04:44 UTC |