in reply to Perl Golf - Renaming MP3s

use File::Find;find sub{/\.mp3$/&&rename$_,substr$_,3},".";

or

use File::Find;find{/\.mp3$/&&rename$_,substr$_,3}".";

if find was declared with proto (&$);

I tried replacing substr$_,3 with s/..-/&&$_, but it modified the first $_ (weird? isn't the comma operator supposed to evalute left, and then right?)

bonus - it passes strict.

Update: Formatting was icky, so I added line breaks.

-nuffin
zz zZ Z Z #!perl

Replies are listed 'Best First'.
Re^2: Perl Golf - Renaming MP3s
by Aristotle (Chancellor) on Nov 20, 2002 at 15:44 UTC
    isn't the comma operator supposed to evalute left, and then right?
    But there's no comma operator here - that's a list. A comma is a list element separator in list context and a comma operator in scalar context. There's no such thing as a list in scalar context and no such thing as a comma op in list context.

    Makeshifts last the longest.

Re: Re: Perl Golf - Renaming MP3s
by Mr. Muskrat (Canon) on Nov 18, 2002 at 22:47 UTC

    And if the track number is more than 2 digits?

    Update: Oops! It seems that I didn't read the challenge carefully.
    buzzcutbudda specified that the track number would only be two digits.
    Thanks for the heads up, nothingmuch.

      I think I would go for ()=/\d+-(.*)/g

      -nuffin
      zz zZ Z Z #!perl

      The id3v1 spec only has space for a two-digit track number. (IIRC, theoreticaly, you could put any two characters in, so you could count in hex, base-36, or whatever if you need more space, up to a theoretical max of 254**2, with any two chars, other then \0, which probably has special meaning. I don't remember id3 that well off the top of my head.)


      Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

      I believe it's the case that the CD spec itself limits a disc to 99 tracks anyway.