#!/usr/bin/perl
#
#  This script is used to globally substitute a string in specified file:
#
#  Usage:
#
#           substitute $ARGV[0] $ARGV[1] $ARGV[2]
#
#  where
#
#           $ARGV[0]    file name
#           $ARGV[1]    old string
#           $ARGV[2]    new string
#

use strict;
my $file = $ARGV[0];
my $tmp = "tmp.$$";
open(FILE, "$file");
open(TMP, ">$tmp") || die "Can't open tmp file";
$/=undef;
my $string = <FILE>;
close FILE;

$string=~ s|$ARGV[1]|$ARGV[2]|g;

print TMP "$string";
close(TMP);
rename ($tmp, $file)
