mustaine737
ISP
I have 2 files on disk - oldfilename1.bak and oldfilename2.bak
My goal is to rename oldfilename1.bak to newfilename1.bak, oldfilename2.bak to newfilename2.bak
The old file names are held in a text file called - old.txt, contents ( one on each line) :
oldfilename1
oldfilename2
The new file names are held in a text file called - new.txt, contents (one on each line) :
newfilename1
newfilename2
I'm using this script, but it doesn't work. I think it is because there's a new line when I call the value from the array, can someone please give me any pointers? When I print the array, it looks okay.
*******
#!/usr/bin/perl
open (old,"old.txt") || die ("There was an error opening file: $!");
@oldnames = <old>;
close (old);
open (new,"new.txt") || die ("There was an error opening file: $!");
@newnames = <new> ;
close (new);
for $i (0 .. $#oldnames)
{
$a = "$oldnames[$i]";
$b = "$newnames[$i]";
rename("$a.bak","$b.bak");
}
*************
Thank you, very much.
My goal is to rename oldfilename1.bak to newfilename1.bak, oldfilename2.bak to newfilename2.bak
The old file names are held in a text file called - old.txt, contents ( one on each line) :
oldfilename1
oldfilename2
The new file names are held in a text file called - new.txt, contents (one on each line) :
newfilename1
newfilename2
I'm using this script, but it doesn't work. I think it is because there's a new line when I call the value from the array, can someone please give me any pointers? When I print the array, it looks okay.
*******
#!/usr/bin/perl
open (old,"old.txt") || die ("There was an error opening file: $!");
@oldnames = <old>;
close (old);
open (new,"new.txt") || die ("There was an error opening file: $!");
@newnames = <new> ;
close (new);
for $i (0 .. $#oldnames)
{
$a = "$oldnames[$i]";
$b = "$newnames[$i]";
rename("$a.bak","$b.bak");
}
*************
Thank you, very much.