Incesticide has asked for the wisdom of the Perl Monks concerning the following question:

Hello, this is a Perl script I made to make burning mp3-cd's for my mp3-cd player easier. What I did here was make a script that renames any "live" file of an mp3 existing to mp3file(1).mp3. (All my bands are in different folders in my root music directory, D:/Music. ie: D:/Music/Bandname/Album.) THis is my script, and I want to know if it works and what I can do to make it better: It uses the MP3::ID3v1Tag module, as you can tell. (The module itself generates many warnings;)
#!/usr/bin/perl -w use strict; use mp3::ID3v1Tag; sub Renamer { foreach (@_) { my($artist, $title) = (split '-'); ($artist, $title) = &splitter($artist, $title); rename "$_", "$artist - ${title}(1).mp3" or die "cannot rename + to $_ to ${title}.mp3: $!"; } print "finished Renaming.\n"; } sub Tagger { foreach (@_) { my($artist, $title) = (split '-'); ($artist, $title) = &splitter($artist, $title) my $mp3_file = new MP3::ID3v1Tag($_); $mp3_file->set_title($title) or die "cannot set title: $!"; $mp3_file->set_artist($artist) or die "cannot set title: $!"; $mp3_file->save() or die "Cannot save changes: $!"; } print "finished ID3 Tagging.\n"; } sub splitter { substr($_[0], -1, 1, ''); print "\$_[0] = ${_[0]}END\n"; substr($_[1], 0,1, ''); print "\$_[1] = BEGIN$_[1]\n"; substr($_[1], -4, 4, '') if substr($_[1], -4, 4) eq '.mp3'; return ($_[0], $_[1]); } print "MASS ID3 Tagger and Renamer by Incst. Input a directory or typ +e exit to exit.\n"; while (1) { chomp(my $dir = <STDIN>); if ($dir eq exit) { last; } else { chdir $dir or die "Cannot change to specified directory: $! +"; my @MP3_files = <*.mp3>; &Tagger(@MP3_files); &Renamer(@MP3_files); }
Thats the Perl script. Please reply asap.

Replies are listed 'Best First'.
Re: MP3-CD Burning ID3-Tagger/Renamer for Win 9x
by simon.proctor (Vicar) on Feb 18, 2002 at 23:58 UTC
    I don't have the module and I don't need it but I did notice this line:
    if ($dir eq exit)
    I think you need quotes around exit:
    if ($dir eq 'exit')
    I'd also consider doing a while(<STDIN>) style construct but thats just a personal preference.

    You are also missing a final curly at the bottom. You would notice these errors more easily if you indented your code a little better :)
      thanks alot.
Re: MP3-CD Burning ID3-Tagger/Renamer for Win 9x
by Incesticide (Initiate) on Feb 18, 2002 at 22:54 UTC
    erm, there should be a semicolon where ($artist, $title) = &splitter($artist, $title) is. Sorry about that.