#!/usr/bin/perl
use Getopt::Std;
use MP3::Info;

my @mp3s;

getopts('nfA:T:h');

if ( $opt_h ) {
   print "$0 -f -A <artist> -T <title> -h [mp3 files]\n";  
   print "\t-f flush id3 tag\n";
   print "\t-A <artist> set artist on mp3s specified\n";
   print "\t-T <title> set album title on mp3s specified\n";
   print "\t-n cycle through passed mp3s and add track numbers\n";
   print "\t-h print this help.\n";
   exit;
}


while ( my $f = shift ) {
  if ( -w $f ) {
    push(@mp3s, $f);
  } else { 
    warn "$f not found or writable.\n";
  }
}

die "no mp3s to process\n" unless ( @mp3s );
unless ( $opt_A || $opt_f || $opt_T  || $opt_n ) { die "nothing to do\n"; }

if ( $opt_n ) {
  my $tracknum = 1;
  foreach my $file (@mp3s) {
    my $tag = get_mp3tag($file);
    $tag->{TRACKNUM} = $tracknum++;
    set_mp3tag($file, $tag);
  }
  exit;
}

foreach my $file ( @mp3s ) {
  my $tag;
  if ( $opt_f ) {
    remove_mp3tag($file, "ALL");
    $tag = {};
  } else { 
    $tag = get_mp3tag($file);
  }

  $tag->{ALBUM} = $opt_T if ( $opt_T );
  $tag->{ARTIST} = $opt_A if ( $opt_A );

  set_mp3tag($file, $tag);


  $tag = get_mp3tag($file);
  print "ALBUM: ", $tag->{ALBUM}, " ARTIST: ", $tag->{ARTIST}, $/;
}


syntax highlighted by Code2HTML, v. 0.9.1