Perl eq doesn't match identical variables
I'm working on a perl script to clean up some video filenames and eliminate the extra fields after the name and episode. It's working perfect except for a string check at the end. Before I actually rename the file, if the current file name is identical then there's no point and also I don't want errors about identical file names. The code I'm using is
## Check to see if this is already a good name
if ($vid eq $newfile) {
print "Filename " . $vid . " is OK. \n";
} else {
## Show the old and new names
print "Old File = " . $vid . "\n";
print "New File = " . $newfile . "\n";
}
No matter what I've tried I get the same results. If a file is named My.Show.S01E01.avi then both $vid and $newfile contain that string in debugging, but the script never says "My.Show.S01E01.avi is OK"
Instead I get
Old File = My.Show.S01E01.avi
New File = My.Show.S01E01.avi
############ EDIT ############
Script is fixed, from early testing I had been printing the $newfile variable out to see what it did. Once I started expanding the script I forgot to remove it so the resulting $newfile had \n a the end of it although it didn't show in debugging.
Last edited by GDarkBladE; 10-21-2008 at 05:28 PM.
Reason: Found problem once files were renamed and had newline character on them
|