> How can I do this?

You can do it like this...

# tested
my @stack;

while (<STDIN>) {
  last if /QUIT/;
  push @stack, $_;
}

print "@stack";


Rob

-----Original Message-----
From: Dan Anderson [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 25, 2003 8:23 PM
To: Perl Newbies
Subject: How do I<STDIN> to a stack until a pattern is matched, How do I


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?
$infinite_loop = 1;
while ($infinite_loop)
{
  $temp = <STDIN>;
  if ($temp =~ /QUIT/)
    { 
        $infinite_loop = 0; 
        continue;
    }
  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;
}

Or perhaps something even more concise (and much more perlish)?

Thanks,

Dan



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to