Can't call method "title" on undefined title in Perl script
I'm writing a short Perl script to rename a directory full of MP3 files and re-write some of their ID3 tags using the MP3::Tag module, but I'm having some trouble with it. Whenever I try to run it, I get this error:
Code:
[scuzzy@slackdell /home/scuzzy/music/young_jeezy/unknown_disc]$ ~/fixid3.pl Code:
#!/usr/bin/perl Edit: I have just tried it with and without the quotes on these lines (in red) and yielded the same results: Quote:
|
The error you're getting means that you are trying to call your methods (title being the first one) on an undefined object. I don't think you can access ID3v1 methods like that. You need to use the get_tags() method first to fetch all the tags the mp3 object has access to and then call it directly via the MP3::Tag::ID3v1
I think it will work if you add this after your new() call: $mp3->get_tags(); unless (exists $mp3->{ID3v1}) { # handle error ... } $id3v1 = $mp3->{ID3v1}; $id3v1->title($title); Hope that helps |
It's still not working, but now I at least have a clue why. This is the new segment of code:
Code:
$mp3 = MP3::Tag->new($file); # Creates new object Code:
[scuzzy@slackdell /home/scuzzy/music/young_jeezy/unknown_disc]$ ~/fixid3.pl |
Hmm ... how about dumping out the result of get_tags() and see what we actually get.
Code:
# add this to the top of your code |
OK - This is the current code snippet:
Code:
print "What is the track name? "; Code:
[scuzzy@slackdell /home/scuzzy/music/young_jeezy/unknown_disc]$ ~/fixid3.pl |
Sorry I didn't realize get_tags just returns a list of strings.
Pleasse try the code snippet below and look at my comments for an explanation. Code:
|
Still not working... I'm pretty sure I understand most of the code, and it looks as though it should function (when the Dump is removed that is...). This is the current fix_id3 subroutine:
Code:
sub fix_id3 { Code:
[scuzzy@slackdell /home/scuzzy/music/young_jeezy/unknown_disc]$ ~/fixid3.pl |
qq is double quotes. The difference is that qq will interpret any variables for you unlike q.
For some reason the file you're using only has 'ParseData' and 'LastResort' available. That's why any references to $mp3->{ID3v1} are undefined. I copied the script and ran it on my computer with one of my mp3 files and it worked. This is the output: Code:
(host: waldemar) (user: waldemar) (time= 21:09:06) From the perldoc Code:
# create a new tag |
I cannot thank you enough for you help :) And for once, I understand what was not working. Here is the fully working code:
Code:
#!/usr/bin/perl BTW: The extra variables $id3v1 and @tags were not needed - I've removed them. The code above works exactly as planned :D |
As this is a learning exercise, I've been slowly adding more and more functionality to the script. Right now, I'm trying to add the functionality to verify the ID3's before rewriting them - but the function isn't running. This is the code:
Code:
#!/usr/bin/perl |
You're welcome. I'm glad you got it working.
One thing I just noticed is that you're using "==" for your string comparison. The comparison operator for strings is "eq" and "==" is for numeric values only. That may be causing the issue. |
Same Error!! No Solution!
This is a great thread...I'm beginning to think that this issue is deeper than just a file without tags...I've been fighting the "Can't callmethod " " on undefined value..." error for the past few hours now and can't seem to get a handle on the issue. I actually created two files...one simply edits meta tags and the other takes the name of the actually mp3 and parses it into a foldername THEN edits the meta tag. My goal is to write a program that takes a directory full of uniformly formatted mp3s and parses the names into uniformly named folders and also edits the meta tag of each mp3 using the data collected from parsing the filename:
Here is the metatag part (the part relevant to this thread) Code:
#!/usr/bin/perl Code:
#!/usr/bin/perl Error: Code:
$ perl perlProg.pl |
Quote:
Code:
use strict; |
All times are GMT -5. The time now is 04:23 AM. |