Why doesn't the angle operator localize its use of $_ within a conditional while loop? The implicit localization of $_ by for wonderfully helps tersely coded for-loops avoid incurring "globals side-effect hell." I would guess that the motivation for the for-localization goes something like "the behavior is what most would expect", given that most would expect the effects on loop variables not to persist beyond the scope of the loop. However, I (perhaps naively) think this would apply to the use of $_ by the angle operator within while as well. This is not a rant - I merely wonder if this form of implicit localization was considered and "shot-down" for other reasons and, if so, what those reasons were?

Here is illustrative code...

sub f { $_++ for @_; } use FileHandle; sub angle { my $fh = FileHandle->new(q(echo hi |)) or die "$cmd failed\:$!"; while (<$fh>) {}; #nop } $_ = 1; @a = qw(0 1 2); local $" = ':'; print "original values:\n"; print "\t\$_=>$_\n"; print "\t\@a=>@a\n"; f @a; print "for has modified \@a, using a localized \$_\n"; print "\t\$_=>$_\n"; print "\t\@a=>@a\n"; angle; print "angle has modified a non-localized \$_\n"; print "\t\$_=>$_\n";

In reply to Why doesn't the angle operator localize $_ by welchavw

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.