On Mon, Jun 16, 2003 at 10:33:28PM -0700, Bryan Harris wrote:
> 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 find out what STDIN is connected to with the file
test operators.
$ perldoc -f -X
So if I understood you correctly:
#!/usr/bin/perl -l
use strict;
use warnings;
die usage() if (@ARGV == 0)
or (@ARGV == 1 and -t STDIN);
my $pattern = shift;
my $buffer = '';
while (<>) {
$buffer .= $_;
if (eof) {
local $, = ": ";
my @pre = ($ARGV)[($ARGV eq '-')..0];
print @pre, $1
while $buffer =~ /($pattern)/mgi;
$buffer = '';
}
}
sub usage { "Usage: $0 <PATTERN> [FILES]\n" }
--
Steve
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]