home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 10
/
AU_CD10.iso
/
Updates
/
Perl
/
RPC
/
!Perl
/
scripts
/
SimpleGrep
< prev
next >
Wrap
Text File
|
1998-07-14
|
994b
|
56 lines
#! perl -w
# This version of grep is fully featured, but is written for clarity not speed.
use RISCOS::Throwback 'throwback_info';
use RISCOS::Filespec;
use RISCOS::File 'globlist';
use Getopt::Std;
use vars qw($opt_c $opt_t $opt_v);
delete $SIG{'__DIE__'};
sub printit ($) {
print "$ARGV: " if ($lots); # Only print the filename if more than one
print @_;
}
if (defined $ARGV[0] and $ARGV[0] eq '-throwback') {
$throw = 1;
$pattern = shift;
} else {
$throw = 0;
}
getopts ('ctv');
$pattern = shift @ARGV;
die "$0 [-throwback] [-c] [-v] pattern [files]" unless $pattern;
@ARGV = globlist( @ARGV );
$count = 0;
$throw = 0 if $opt_t;
$lots = @ARGV > 1;
while( <> )
{
next unless $opt_v xor /$pattern/;
$opt_c ? $count++ : printit ($_);
if ($throw)
{
chomp;
throwback_info( $ARGV, $., $_ );
}
} continue {
if (eof) {
printit ("$count\n") if ($opt_c && $count);
$count = 0;
close(ARGV); # Reset line numbers for each file
}
}