Paul Seamons <[EMAIL PROTECTED]> writes:
perl -e '
    use File::Find;            # load the library
    find(sub{
        return if ! -d;        # must be a directory
        return if ! /^(.{5})_/ # match 5 chars and then _
        rename ($_, $1)
            || warn "Err: $_ => $1: $!";
    }, ".");                   # look in "." for files
'
perl -e '
opendir $dh, "."; # open directory inode as a
    handle
   for (readdir $dh) {         # iterate on files in $dh
        next if ! -d;          # must be a directory
        next if ! /^(.{5})_/;  # match 5 chars and then _
        rename($_, $1)
            || warn "Err: $_ => $1: $!"
   }
'

As a sidenote, I think that the above make much better answers to 'how do I?' questions than the one-liner versions. Only perl programmers (and perhaps terminally deranged C programmers) are impressed by squeezing an otherwise legible program onto a single line. The tendency of perl users to throw out unreadable one-liners in response to questions is one thing that kept me from learning perl for a very long time. The above examples, on the other hand, clearly demonstrate nifty perl features like higher-order anonymous subroutines. Just something to keep in mind if you're at all concerned about perl advocacy. If you're not, feel free to ignore. --Levi

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to