Modules look imtimidating at first, but they're really cake. Simply load the module at run time. Wow, that doesn't sound simple at all. Here's what I mean:
#!/usr/bin/perl -w
use MP3::ID3v1Tag;
This allows your code to access the subroutines in MP3::ID3v1Tag. From there, you call them like any other sub.
use MP3::ID3v1Tag; # Adds the library
$mp3_file = new MP3::ID3v1Tag("filename.mp3"); # Creates a new objec
+t called $mp3_file.
$mp3_file->print_tag(); # calls subroutine print_tag() on the file t
+he $mp3_file object is working on (filename.mp3)
if($mp3_file->got_tag()) { # calls subroutine got_tag(), which will
+return 1 if the tag exists, 0 if not.
$mp3_file->set_title($title); # calls subroutine set_title(),
+which will set the title to the value $title. In normal practice, you
+ probably would have parsed out of the filename
$save_status = $mp3_file->save(); # calls subroutine save(), c
+ommitting your changes.
}
Clear as mud? Think of a module as a big bag of subroutines that you don't have to write. Just read the documentation, and you'll have all you need to know about how to use them, and all the dirty work happens behind the scenes.
Over time I've found that a new project begins by searching CPAN for relavent modules. If you can find one, you may find that 90% of your work is already done for you.
One more thing, as you continue coding perl, I can't stress enough how useful The Perl Cookbook will be. It's one book I wish I'd bought on my first day coding.
-Logan
"What do I want? I'm an American. I want more." |