#!/usr/bin/perl -w -i~ 

# Wee script to replace strings (or other regexps with a string of your
# choice.  Inspired by the sh script of the same name, which kept mangling
# my chmod u+x, and occasionally deleted my files (if I gave it a bad
# input).  
#                        Written by David Roundy in March 2000.
#
# Modified to deal with $1, $2, $3, \n, \t, etc. in replacement strings.
# (use single quotes on command line to use this feature).
#
#                        Modified by Chris Krenn in January 2001.

if ($#ARGV < 2) {
    print $#ARGV;
    die "Usage:  $0 <oldstr> <newstr> [files]\n";
}

$old = shift(@ARGV);
$new = shift(@ARGV);
eval { "" =~ /$old/; 1} or die "$0: Bad pattern $old: $@\n";
eval { "" =~ /$new/; 1} or die "$0: Bad pattern $new: $@\n";
while (<>) {
    if (/$old/) {
        print STDERR "* $_";
        eval "s/$old/$new/";
        print STDERR "> $_";
    }
    print $_;
}




