> I, for one, would be grateful if your would post your perl snippet with
> newlines and formatting.

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: $!"
   }
' 

> To your question, I would argue, "yes.  Yes they are sooo much more
> intuitive."

Possibly to read, but not necessarily to write - but that is again based upon 
the languages one is versed in.  While it is neat that bash supports
control structures and it is an interesting hack how it does, it is not really
intuitive to somebody writing bash scripts.  Perl is anything but intuitive 
until you have learned a little - but the same can really be said for all 
languages.

> Most of us on this list, which includes me, are not as well-versed in
> bash as you are in perl.

I think there are some pretty great bash people on the list.  I just pretend 
to know what I'm doing (which is good enough for most things).

> Yet bash scripts are often, while blunt and 
> brutal, easier to understand.

Often is the good phrase here.  I have learned
what the following means.

 if [ -z "$TZ" -a -e /etc/timezone ]; then
 fi

But it is entirely subjective if that is easier to understand than

  if (length $TZ and -e "/etc/timezone") {
  }

> I have seen malicious perl one-liners before (I know yours is not!).

How do you know mine are not. :)  Thank you for the vote of confidence.

> I  have also seen malicious bash scripts before.  But I can at least tell
> you why the bash script was malicious. To this day I don't know what the
> perl scripts do.

I think Perl can make it easier (well trivial actually) to hide malicious 
code.  But any language can hide evil behavior and if you aren't familiar 
with the language there will be little chance of seeing it.

> In the hands of the adept, perl is powerful magic indeed.

It is perhaps even more powerful in the hands of the inept. :)

> I believe there is a rename utility that is pretty standard that can
> also do this from a shell prompt.

Wow - that is cool.  I didn't know that existed.  I like that better than all 
of our solutions so far.  Thank you for mentioning that.

rename -v 's/^(.{5})_.*/$1/' *

That is short.  You still have to understand perl regex, but that is pretty 
nice.

Paul

/*
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