Thanks for the replies. Here is an updated snippet:
#!/usr/bin/perl print "Enter the <dir> where the mp3's are found: "; chomp ($dir = <stdin>); chdir($dir) or die "Canot change $dir :$!\n"; opendir(DIR, $dir) or die "Cannot open $dir:$!\n"; @songs = readdir(DIR); closedir(DIR); @songs=grep(/(.mp3)|(.MP3)|(.mP3)|(.Mp3)/,@songs); foreach(@songs) { @id = id3check($_); if($id[0] && $id[1]) { rename $_,"$id[0] - $id[1].mp3"; print "$id[0] - $id[1].mp3\n"; } elsif($_ =~ m/(\s*[^-]*)-\s*([^.]*).mp3/i) { my @id; $id[0] = $1; $id[1] = $2; s/\s*$|{|}//g for ($id[0], $id[1]); rename $_,"$id[0] - $id[1].mp3"; print "$id[0] - $id[1]\n"; } else { print "Could not rename $_\n"; } } sub id3check { if (open(FILE, '+<' . $_[0])) { my @id; binmode FILE; seek FILE,-128,2; read FILE,$tag,3; if($tag eq "TAG") { read FILE,$id[0],30; read FILE,$id[1],30; s/\s*$|{|}//g for ($id[0],$id[1]); return @id; } } }

In reply to Re: Re: Mp3 Renamer by Anonymous Monk
in thread Mp3 Renamer by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.