[lug] Perl question

Bob Collins bcollins at csd.net
Fri Mar 31 14:41:26 MST 2000


I have a number files I want to rename to lower case, so I went my "Perl
Cookbook" and found exactly what I needed, "rename" on page 327 in my
book.  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.


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.

This script is attributed to Larry Wall, but I think something must be
missing or incorrect in the script.

Help will be appreciated, I have spent a great deal of time on it with
no success.  


-- 
Regards,
Bob Collins
                         Mailto:bcollins at csd.net
-------------- next part --------------
#!/usr/bin/perl -w
# rename - Larry's filename fixer
$op = shift or die "Usage: rename expr [files]\n";
chomp(@ARGV = <STDIN>) unless @ARGV;
for (@ARGV) {
    $was = $_;
    eval $op;
    die $@ if $@;
    rename($was,$_) unless $was eq $_;
}


More information about the LUG mailing list