Dan Anderson wrote: > Is there an easy way to read <STDIN> into a stack until some pattern is > matched and then break. I tried all sorts of (error producing) code, > but nothing seemed to work. I ended up with: > > #! /usr/bin/perl > > #can I make this more concise?
use strict; use warnings; # and test with both turned on before posting, please. > > $infinite_loop = 1; > while ($infinite_loop) > { > $temp = <STDIN>; > if ($temp =~ /QUIT/) > { > $infinite_loop = 0; > continue; Don't do this. Please do not assume that any Perl keyword takes its meanng from that used in other languages. Some do. Many, including continue, do not. It is advisible, before using any Perl function, to prompt> perldoc -f function_name to ensure that you know how the function was meant to be used. > > } > push @thestack, $temp; > } > > I've got a funny feeling that perl will let me make the above 15 lines > of code /much/ more concise. How can I do this? > > Is there any way to do something like? > > while (1) > { > push @thestack, <STDIN> unless <STDIN> =~ /QUIT/; > last if <STDIN> =~ continue; If you are looking for the string 'continue' in the text being read, you should use a regex. If you are trying to use it for flow control, the comments above apply here, also. Try doing without continue, and the problem should become easy. > > } > > Or perhaps something even more concise (and much more perlish)? > > Thanks, Why not just let the 'QUIT' line go into the stack, then pop and discard it when you start processing the stack? Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]