|Pathologically Eclectic Rubbish Lister|
Re: Copy Mp3s By Genreby sacked (Hermit)
|on Apr 26, 2004 at 22:29 UTC||Need Help??|
Nice work! This looks good, and useful, too. Here are a few suggestions:
You open a filehandle FL to each file you examine, but you never read from it. I would remove the code related to this filehandle:
Inside a subroutine, you should use return rather than next. If you use the code as is, you will see warnings from Perl such as "exiting subroutine via next at script.pl line...":
$tag = get_mp3tag($_) or print "Could not access tag on $_\n" and next;
$tag = get_mp3tag($_) or print "Could not access tag on $_\n" and return;
For portability, use File::Spec to generate file or directory names:
File::Path::mkpath raises an exception on error. You'll want to wrap that call in eval. Also, the second argument is a boolean flag that controls printing of the directories as they are created. The third argument is the mode, for which you'll need to have execute permissions on if you want to create subdirectories:
Finally, as a simple style change, you can reduce the indentation level of the code in your wanted subroutine if you use the statement modifier forms of if/unless.
Here is a different version of your script with the changes described above:
You can make the script even more useful by allowing the user to specify the genre, source directory, and destination directories on the command line.