#!/usr/bin/perl # # $Id$ # eval "exec /usr/local/bin/perl -S $0 $*" if $running_under_some_shell; require 'getopts.pl'; &Getopts("p:vh"); # help, pattern file, verbose, if ($opt_h || ! $opt_p) { print STDERR <) { chop; s/#.*//; next if /^$/; ($orig, $new, $junk, @rest) = split; next if ( ! $orig || ! $new || $junk); # <2 or >2 patterns die "pattern appears 2x: '$orig' in '$pattern_file'--" if defined($patterns{$orig}); $patterns{$orig} = $new; } close PATTERNS; # walk thru each line in each file $infile = '-' ; $outfile = '-' ; if ( $#ARGV > -1 ) { $infile = "@ARGV[0]" ; shift @ARGV ; } if ( $#ARGV > -1 ) { $outfile = "@ARGV[0]" ; shift @ARGV ; } open (INFILE, "<$infile") || die "could not open input file $infile: $!"; $line = join('',) ; close INFILE; print STDERR "$outfile\t"; open (OUTFILE, ">$outfile") || die "could not open output file $outfile: $!"; foreach $key (keys %patterns) { if ( $line =~ s/\b$key\b/$patterns{$key}/ge ) { print STDERR "." ; } } print OUTFILE $line ; print STDERR "\n"; close OUTFILE;