3
# This perl script replaces a string with another string.
4
# Here it is allowd for file_in and file_out to be the
10
"Use: string-replace.pl find_string replacement_string file_in file_out\n";
11
if( scalar(@ARGV) < 4 ) {
12
print STDERR $g_use_msg;
16
my $find_string = shift;
17
my $replacement_string = shift;
18
my $file_in_name = shift;
19
my $file_out_name = shift;
22
if($file_in_name=~/CVS/) {
23
# print "Do not replace in CVS\n";
27
open FILE_IN, "<$file_in_name" || die "The file $file_in_name could not be opended for input\n";
28
my @file_in_array = <FILE_IN>;
32
my $did_replacement = 0;
33
foreach(@file_in_array) {
35
$did_replacement = 1 if $_=~s/$find_string/$replacement_string/g;
37
push @file_out_array, $_;
39
if($did_replacement || $file_out_name ne $file_in_name) {
40
open FILE_OUT, ">$file_out_name" || die "The file $file_out_name could not be opended for output\n";
41
print FILE_OUT @file_out_array;