Jim Gibson wrote:

You are not likely to find such a specific tool. However, you can
develop your own tool.

Here is a renaming program adapted from the one in the Perl Cookbook,
Recipe 9.9:

#!/usr/bin/perl
#
# rename
#
# perl script to rename files
#
# Usage:
#
# rename perlexpr [files]
#

($op = shift) ||
die
"Usage: rename perlexpr [filenames]
where perlexpr is any perl expression that modifies \$\_:
's/old/new/'
'\$\_ .= \".ext\"'
'tr[A-Z][a-z]'\n";

You should use a here doc so you don't have to backslash everything:

my $op = shift or die <<'USAGE';
Usage: rename perlexpr [filenames]
where perlexpr is any perl expression that modifies $_:
   's/old/new/'
   '$_ .= ".ext"'
   'tr/A-Z/a-z/'
USAGE


if( !@ARGV ) {
@ARGV = <STDIN>;
chop( @ARGV );

You should use chomp instaed of chop:

    chomp( @ARGV = <STDIN> );


}
for( @ARGV ) {
$was = $_;
eval $op;
die $@ if $@;
rename($was,$_) unless $was eq $_;
}

That looks a lot like Larry's rename script which is distributed with some versions of Linux.



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to