I
ironmanda
I'm trying to build a general way of handling search and replace
of strings. The regexp in the commented out part works perfectly.
But, the foreach part doesn't work. The thing is, \1 is being
interpreted literally. Any ideas?
David
#!/usr/local/bin/perl
my $str="http://www.xxx.com/yyy/zzz/25331/2";
$repurl{"([0-9]*)\\/[0-9]+\$"}="\\1";
# $str=~s/([0-9]*)\/[0-9]+$/\1/g;
# print "$str\n";
# exit 0;
foreach $key (sort keys %repurl) {
print "$key - $repurl{$key}\n";
$str=~s/$key/$repurl{$key}/g;
}
print "$str\n";
of strings. The regexp in the commented out part works perfectly.
But, the foreach part doesn't work. The thing is, \1 is being
interpreted literally. Any ideas?
David
#!/usr/local/bin/perl
my $str="http://www.xxx.com/yyy/zzz/25331/2";
$repurl{"([0-9]*)\\/[0-9]+\$"}="\\1";
# $str=~s/([0-9]*)\/[0-9]+$/\1/g;
# print "$str\n";
# exit 0;
foreach $key (sort keys %repurl) {
print "$key - $repurl{$key}\n";
$str=~s/$key/$repurl{$key}/g;
}
print "$str\n";