LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-21-2008, 04:59 PM   #1
GDarkBladE
Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 38

Rep: Reputation: 17
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
 
Old 10-21-2008, 05:48 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
You could also use -f to check if file exists maybe ?
if(-f $newfile) { print "$newfile exists\n"; }
 
Old 10-22-2008, 03:04 AM   #3
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
Have you checked for whitespace at the end of the string?
 
Old 10-22-2008, 08:33 AM   #4
GDarkBladE
Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 38

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by burschik View Post
Have you checked for whitespace at the end of the string?
You were really close. Note the EDIT on the original post. What happened was during testing where I build the new filename I had a \n at the end. After converting the string to the $newfile variable I forgot to remove it. During debugging it never showed there was a newline on the end of the variable so they looked identical. But after posting the thread I added the rest of the script to rename the files and tested it all the files were had .avi// / at the end and were effectively useless. Once I saw that I looked at the script and found and removed the \n and it's fixed.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Maximizing Set Match Probability Using Perl On Linux Or Unix LXer Syndicated Linux News 0 09-12-2008 01:30 PM
irrelevant characters match in PERL pattern matching gaynut Programming 2 08-21-2008 10:52 PM
Perl Regex multiline match issues adymcc Linux - General 2 03-31-2008 09:45 AM
perl regular expression a char match richikiki Programming 8 07-19-2006 03:37 AM
perl pattern match question lluciano Programming 4 02-28-2006 05:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration