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:
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.my $line; while ( (print "list of letters: "),$line=<>, $line !~ /\s*quit|exit|q +\s*$/i) {..do something with this line...}
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |