[boulder.pm] Perl question

Jason Wells wellsj at cs.colorado.edu
Fri Mar 31 16:21:22 CST 2000


Bob Collins wrote:

> The "rename" script is sent as an attachment.  The script can be
> executed as:
>
> rename 'tr/A-Z/a-z/ unless /^Make/' *
>
> This should change files to lowercase.  If you understand the " unless
> /^Make/ " part I would be interested in an explanation.

This is so Makefiles aren't renamed so 'make' can still find them.

> I am trying to get it to work in it's simplest form, "rename file.name
> newfile.name".  I create a file AB.C and try to rename it to ab.c by
> executing:
>
> perl -d name AB.C ab.c
>
> I watch it step throug with no errors.  The script terminates without
> changing anything because $was is equal to $_.  Which it is set to in
> the script.

You're not passing an operation to the script.  That's what the 'tr/A-Z/a-z/
unless /^Make/' is for.  It becomes $op, which is later evaluated on each
file.  This allows the script to handle all sorts of different operations
through regular expressions.

So, to do what you wanted to do you'd execute:

perl -d name 'tr/A-Z/a-z/' AB.C

-Jason




More information about the Boulder-pm mailing list