J
John
Hi,
I'm using this from http://www.perldoc.com/perl5.004_05/pod/perlfaq5.html to
do a string substitution in a HTML file:
$old = $file;
$new = "$file.tmp.$$";
$bak = "$file.bak";
open(OLD, "< $old") or die "can't open $old: $!";
open(NEW, "> $new") or die "can't open $new: $!";
# Correct typos, preserving case
while (<OLD>) {
...
###########################The below concerns me
if ($_ =~ "A HREF=") {
my $link = $_;
$link =~ s/href="([^"]+)"/my
$x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
}
(print NEW $_);
}
###########################The above concerns me
close(OLD) or die "can't close $old: $!";
close(NEW) or die "can't close $new: $!";
rename($old, $bak) or die "can't rename $old to $bak: $!";
rename($new, $old) or die "can't rename $new to $old: $!";
I'm expecting the contents of the file to change from:
<A HREF="One/One/one/One.html"> One link
to:
<A HREF="Two/Two/one/Two.html"> One link
but it still reads:
<A HREF="One/One/one/One.html"> One link
Any help will be greatly appreciated...
I'm using this from http://www.perldoc.com/perl5.004_05/pod/perlfaq5.html to
do a string substitution in a HTML file:
$old = $file;
$new = "$file.tmp.$$";
$bak = "$file.bak";
open(OLD, "< $old") or die "can't open $old: $!";
open(NEW, "> $new") or die "can't open $new: $!";
# Correct typos, preserving case
while (<OLD>) {
...
###########################The below concerns me
if ($_ =~ "A HREF=") {
my $link = $_;
$link =~ s/href="([^"]+)"/my
$x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
}
(print NEW $_);
}
###########################The above concerns me
close(OLD) or die "can't close $old: $!";
close(NEW) or die "can't close $new: $!";
rename($old, $bak) or die "can't rename $old to $bak: $!";
rename($new, $old) or die "can't rename $new to $old: $!";
I'm expecting the contents of the file to change from:
<A HREF="One/One/one/One.html"> One link
to:
<A HREF="Two/Two/one/Two.html"> One link
but it still reads:
<A HREF="One/One/one/One.html"> One link
Any help will be greatly appreciated...