I disagree with your recommended code, but not your data.

For a while loop, I like to write the main exit condition into the while statement. There could be many ways for the loop to exit past the main, expected condition. However, I code the "most likely" case into the conditional statement.

Example:

my $line; while ( (print "list of letters: "),$line=<>, $line !~ /\s*quit|exit|q +\s*$/i) {..do something with this line...}
In the above, a "my" variable cannot be defined and be used within the same comma statement or logical "and" statement, hence the "my $line;" before the loop conditional.

I do recommend using named variables for all while loops that go into production code.

In the above, using "and" instead of the "," would be just fine. The truthfulness of a comma statement only has to do with the value of the last part.


In reply to Re^2: $_ not set in while <> by Marshall
in thread $_ not set in while <> by pidloop

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.