I was about to tell you that I'm not sure whether I would recommend it because the

while (<>) {...}

is associated with quite a lot of dwimmy magic that would would vanish if you amend the construct that way, but when I was about to give you an example it turned out that it was actually a counter-example showing I was plainly wrong:

pilsner:~ [11:58:42]$ perl -MO=Deparse -e 'while (<>) {}' while (defined($_ = <ARGV>)) { (); } -e syntax OK pilsner:~ [11:59:05]$ perl -MO=Deparse -e 'while (local $_=<>) {}' while (defined(local $_ = <ARGV>)) { (); } -e syntax OK

Thus perl is smart enough to still add the definedness test even in that case: I stand corrected, and you taught me something new. I am fairly sure this was not the case with all perls, but I have now tested with 5.8.8 which is the oldest one I have currently access to, and it supports this feature. I don't know when it was actually introduced. I used to believe that it would only work with a variable assignment, but not if a local (or anything else) was preprended to it...

I still feel like claiming that in most cases using while (<>) {...} responsibly would be enough.

--
If you can't understand the incipit, then please check the IPB Campaign.

In reply to Re^2: Just when you thought you'd got it: 'foreach $f (@foo)' vs 'foreach (@foo)' by blazar
in thread Just when you thought you'd got it: 'foreach $f (@foo)' vs 'foreach (@foo)' by gone2015

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.