----- Original Message ----- 
From: "Bryan Harris" <[EMAIL PROTECTED]>
To: "Beginners Perl" <[EMAIL PROTECTED]>
Sent: Tuesday, June 17, 2003 1:33 AM
Subject: Re: while (<>)


>
> >   #!/usr/bin/perl
> >
> >   my $showme = shift
> >     or die "Usage: $0 <PATTERN> [FILES]\n";
> >
> >   while (defined(my $line = <>)) {
> >     $_ .= $line;
> >     next unless eof;                             # [1]
> >
> >     my $prefix = ($ARGV eq '-')? '' : "$ARGV: "; # [2]
> >
> >     print "${prefix}$1\n" while /($showme)/mgi;
> >     $_ = '';
> >   }
>
>
> Pretty neat, Steve, thanks.  The only thing that'd be nice to fix is
making
> it so it gives the usage line if you enter:
>
> % showme 'ah\d'
>
> instead of waiting for STDIN.  Aside from that it works perfectly.  And I
> learned a few things in the process.
you can do that by simply adding to second line:

my $showme = shift,@ARGV == 1      or die "Usage: $0 <PATTERN> [FILES]\n";

This will stop:
% showme 'ah\d'
% showme 'ah\d' filee1 anything after


> Thanks again.
>
> - Bryan
>
>
> -- 
> 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