[boulder.pm] Perl question

Jason Van Slyke jvanslyk at matchlogic.com
Fri Mar 31 16:20:50 CST 2000


Bob,

Ok, here is what I did:

#!/usr/local/bin/perl -w
# change uc file names of lc file names ;

foreach $oldfile (<*.pl>) {
        $newfile = lc($oldfile) ;
        print "\n\$oldfile=$oldfile\n\$newfile=$newfile\n\n" ;
        rename ($oldfile, $newfile) ;
}

foreach $filename (<*.pl>) {
        print "\n\$filename=$filename\n\n" ;
}

With these results:

/data01/jvsdev/trythis:>perl -w renthis.pl 

$oldfile=AB.pl
$newfile=ab.pl


$oldfile=renthis.pl
$newfile=renthis.pl


$filename=ab.pl


$filename=renthis.pl

Looks like it works to me.  Not elegant; but useful, simple &
understandable.

Jason
-----Original Message-----
From: Bob Collins [mailto:bcollins at csd.net]
Sent: Friday, March 31, 2000 2:41 PM
To: undisclosed-recipients
Subject: [boulder.pm] Perl question


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



More information about the Boulder-pm mailing list