E
Ethan
This is adding more detail to my previous post. As mentioned, I'm
trying to write a simple search and replace script. My current version
is copied below. When I run it on a directory tree of files, for each
file the first occurance of the search string IS replaced, but NONE of
the others are replaced.
If I could just get it to replace all of the occurances, then I'd be
in business. Any help or information would be greatly appreciated.
Thanks!
E
sub doReplace
{
my @outLines; #Data we are going to output
my $line; #Data we are reading line by line
# Only parse files that end in .htm
if ( $File::Find::name =~ /\.htm$/ )
{
print "\nprocessing $_\n";
open (FILE, $File::Find::name ) or
die "Cannot open file: $!";
$backupFileName = $File::Find::name . ".bak";
system("cp $File::Find::name $backupFileName");
while ( $line = <FILE> )
{
print " |"; # To show that something's happening
#$line =~ s/\.jsp/.htm/; # Only works the first time
# Rest of the ".jsp"s untouched
push(@outLines, $line);
}
close FILE;
open ( OUTFILE, ">$File::Find::name" ) or
die "Cannot open file: $!";
print ( OUTFILE @outLines );
close ( OUTFILE );
undef( @outLines );
}
}
trying to write a simple search and replace script. My current version
is copied below. When I run it on a directory tree of files, for each
file the first occurance of the search string IS replaced, but NONE of
the others are replaced.
If I could just get it to replace all of the occurances, then I'd be
in business. Any help or information would be greatly appreciated.
Thanks!
E
sub doReplace
{
my @outLines; #Data we are going to output
my $line; #Data we are reading line by line
# Only parse files that end in .htm
if ( $File::Find::name =~ /\.htm$/ )
{
print "\nprocessing $_\n";
open (FILE, $File::Find::name ) or
die "Cannot open file: $!";
$backupFileName = $File::Find::name . ".bak";
system("cp $File::Find::name $backupFileName");
while ( $line = <FILE> )
{
print " |"; # To show that something's happening
#$line =~ s/\.jsp/.htm/; # Only works the first time
# Rest of the ".jsp"s untouched
push(@outLines, $line);
}
close FILE;
open ( OUTFILE, ">$File::Find::name" ) or
die "Cannot open file: $!";
print ( OUTFILE @outLines );
close ( OUTFILE );
undef( @outLines );
}
}