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.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^8: no chunk is too small by BrowserUk
in thread Last undefines a for loop's itererator? by BUU

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.