[boulder.pm] Perl question

Micah R. Condon micah at webdezyne.com
Fri Mar 31 16:21:05 CST 2000


Hi Bob -

The problem is in your command line arguments:
you don't need quotes around the 'tr/A-Z/a-z / unless
/^Make/' - with the quotes in place, my system would
just see a string but not try to evaluate the
translation. Without the quotes, it worked for me.

the 'unless /^Make/' part excludes any files that begin
with 'Make', like Makefile.pl

the command perl -d name AB.C ab.c wouldn't work with
this script, because 'AB.C' would be seen as a command
to evaluate, rather than as a filename.  Instead, you'd
want to use something like this:

#!/usr/bin/perl -w
# rename - Micah's filename fixer :-)
$file1 = shift;
$file2 = shift;
rename($file1,$file2) unless $file1 eq $file2;

You could also set $op = 'tr/A-Z/a-z'; instead of
always supplying a command line argument

Hope that helps!




Micah R. Condon, Owner
Webdezyne: Affordable Custom Web Programming

-------------------------------------------------------
-------------------------


http://www.webdezyne.com * micahc at webdezyne.com *
1-800-863-2740


-----Original Message-----
From: owner-boulder-pm-list at pm.org
[mailto:owner-boulder-pm-list at pm.org]On Behalf Of Bob
Collins
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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/archives/boulder-pm/attachments/20000331/e49fdaa9/attachment.htm


More information about the Boulder-pm mailing list