Trying to do string replacement inside html files. E.g., 68yrbkpg10.htm is 
to be replaced with 68yrbkpg10sr.htm. This doesn't work quite right. Also, 
where did the $t1 come from in the s// line? It is not defined earlier. 
thanks ahead of time.

while (m/(\w*68yrbkpg(\d+)\.htm)/) {
        ($t2 = $t = $1) =~ tr/$1/68yrbkpg$2sr\.htm/;
        s/$t1/$t2/;
}

Here's the whole script:

# yrbksr - replace occurances of 68yrbkpgDD.htm with 68yrbkpgDDsr.htm where 
DD is one or two digits.
#
#
use File::Copy;
print "The directory is: ";
chomp( $dir = <STDIN> );
$dirorig = $dir;
opendir(D, $dir);
@files = readdir(D);
print "@files\n";
for $filename (@files)  {
   #if (/^\./) { print "filename matches if and is ---$filename---\n"; }
   #else { print "Filename does NOT match and is ---$filename---\n";}
   next if $filename=~/^\./;
   #print "\$filename is $filename\n";
   $filename=($dir .= $filename);
   #print "next, make a \.bak file. filename is now $filename\n";
   move( $filename, "$filename.bak");
   open(OLD, "$filename.bak") or die "Cannot open $filename.bak : $!\n";
   #print "OLD\.bak opened\n";
   open (NEW, ">$filename") or die "Cannot open $filename for read :$!\n";
   #print "NEW file opened for writing\n";
   while (<OLD>)   {
     #print "stuck in the while";
     while (m/(\w*68yrbkpg(\d+)\.htm)/) {
        #$search = "68yrbkpg";
        #$replacement = "68yrbkpgsr";
        ($t2 = $t = $1) =~ tr/$1/68yrbkpg$2sr\.htm/;
        s/$t1/$t2/;
        print "After s'ing, \$t2=$t2, \$2=$2, \$1=$1\n";
        #print "In 1st while after s'ing, \$1=$1, \$2=$2, \$t=$t, \$t1=$t1, 
\$t2=$t2\n";
     }
     
   print NEW;
   }
   close NEW;
   close OLD;
   $filename = "";
   #print "Reinited the variable \$filename which is now: 
---$filename---\n";
   $dir = $dirorig;
}

---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to