First, thank you for your help. Second, please bear with me as I'm a
perl noob.
I assume that $_ is the last thing gotten by <STDIN>. will regexes
always default to using $_? I think that's right, but when I try:
while (!(<STDIN> =~ /QUIT/))
{ push @stack, $_; }
print @stack;
it doesn't print anything (although it compiles).
So I typed use warnings; at the top and I get a lot of errors about
using an uninitialized variable (@stack). Now I assume that @stack
comes into scope as local to that while loop, but typing:
my @stack;
our @stack;
local @stack;
Before the loop do nothing. Am I missing something?
Thanks again for your help,
-Dan
On Thu, 2003-09-25 at 20:29, Hanson, Rob wrote:
> > 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]