In the January 2003 issue of The Perl Review, I write about separating code, configuration, and presentation.
Since I was working with MP3 files today, I decided to separate code, configuration, and logic in my little mp3info script which I use when I work on Mac::iTunes. The script does not come with the module, although you can get it from CVS (which has the full file with documentation).
use ConfigReader::Simple; use MP3::Info; use Text::Template qw(fill_in_file);
my $Config = "$ENV{HOME}/.mp3info.rc";
my $config = ConfigReader::Simple->new( $Config ); die "Could not get configuration" unless ref $config;
my $template = $config->template; die "Could not find template [$template]!" unless -e $template;
foreach my $file ( @ARGV ) { my $tag = get_mp3tag($file) or die "No TAG info"; my $info = get_mp3info($file) or die "No info";
my $hash = { %$tag, %$info, file => $file, size => -s $file };
print fill_in_file( $template, HASH => $hash ); }
{ join "\n\t", $file, $TITLE, $ARTIST, $SIZE, $size, }