http://www.perlmonks.org?node_id=11133576


in reply to Re^3: $_ not set in while <>
in thread $_ not set in while <>

The condition is not "dense".
The condition is whether or not the input line is "quit" or some form of that.
All that matters is the part after the last comma.

Works fine for me:

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>
Update: I guess this could be, using "and" instead of comma.
print() does return a true value, but nobody checks it.
while ( (print "list of letters: ") and defined ($line=<>) and $line ! +~ /\s*quit|exit|q +\s*$/i)
The comma operator is completely fine in Perl. This is more common in C code.

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