E
Ethan
Hi. I'm trying to write a script that will search through files in a
website and replace certain strings with others (in some cases just
delete them). My overall goal is to convert a JSP site to plain html
removing all the JSP code and adding some SSIs.
I adapted the subroutine below which was posted on 10/8 to devshed.com
by "raklet". When I run it there are no error messages and the print
statements work as expected. However when I go to look at the files,
in some files it appears that nothing has happened, and in other cases
all data in the file has been removed.
I would be grateful for any comments or information on why this isn't
working.
Alternately, if anyone could point me in the direction of a better
solution altogether that would be great too.
I'm not a Perl expert sorry to say.
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: $!";
while ( $line = <FILE> )
{
$line =~ s/\.jsp$/.htm/i;
$line =~ s/<jsp:setProperty.+\>//i;
$line =~ s/<jsp:useBean.+\>//i;
push(@outLines, $line);
}
close FILE;
open ( OUTFILE, ">$File::Find::name" ) or
die "Cannot open file: $!";
print ( OUTFILE @outLines );
close ( OUTFILE );
undef( @outLines );
}
}
website and replace certain strings with others (in some cases just
delete them). My overall goal is to convert a JSP site to plain html
removing all the JSP code and adding some SSIs.
I adapted the subroutine below which was posted on 10/8 to devshed.com
by "raklet". When I run it there are no error messages and the print
statements work as expected. However when I go to look at the files,
in some files it appears that nothing has happened, and in other cases
all data in the file has been removed.
I would be grateful for any comments or information on why this isn't
working.
Alternately, if anyone could point me in the direction of a better
solution altogether that would be great too.
I'm not a Perl expert sorry to say.
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: $!";
while ( $line = <FILE> )
{
$line =~ s/\.jsp$/.htm/i;
$line =~ s/<jsp:setProperty.+\>//i;
$line =~ s/<jsp:useBean.+\>//i;
push(@outLines, $line);
}
close FILE;
open ( OUTFILE, ">$File::Find::name" ) or
die "Cannot open file: $!";
print ( OUTFILE @outLines );
close ( OUTFILE );
undef( @outLines );
}
}