Works fine for me:
Update: I guess this could be, using "and" instead of comma.use strict; use warnings; my $line; while ( (print "list of letters: "),$line=<>, $line !~ /\s*quit|exit|q +\s*$/i) { print "doing something with $line\n"} __END__ Example run: C:\Users\xxx\Documents\PerlProjects\Monks>perl commandloopX.pl list of letters: 234 doing something with 234 list of letters: asdf doing something with asdf list of letters: quit C:\Users\xxx\Documents\PerlProjects\Monks>
The comma operator is completely fine in Perl. This is more common in C code.while ( (print "list of letters: ") and defined ($line=<>) and $line ! +~ /\s*quit|exit|q +\s*$/i)
Update: Oh, the parens around the print are required in order to get the prompt onto the screen.
I never use a while(1) statement except perhaps in a server process.
Another Update:
I did run your code. I did require the addition of a "my declaration" for $line.
Your code does work albeit as wordy and hard to understand as it is.
I am sure that there are many Monks who will disagree with style issues!
use strict; use warnings; my $line; while (1) { print "list of letters: "; defined( $line = <> ) or last; $line !~ /\s*quit|exit|q\s*$/i or last; # Do something with $line. } __END__ C:\Users\xxxx\Documents\PerlProjects\Monks>perl commandloopX3.pl list of letters: adf list of letters: 123 list of letters: q
In reply to Re^4: $_ not set in while <>
by Marshall
in thread $_ not set in while <>
by pidloop
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |