On Wed, Apr 10, 2002 at 10:11:28AM -0400, Craig Sharp wrote: > Allison, > > Try this script. I found it out on the net. My need was to rename a > set of files but I don't see any reason that this couldn't rename a > single file. > > #!/usr/local/bin/perl > # > # Usage: rename perlexpr [files] > > ($regexp = shift @ARGV) || die "Usage: rename perlexpr [filenames]\n"; > > if (!@ARGV) { > @ARGV = <STDIN>; > chomp(@ARGV); > } > > > foreach $_ (@ARGV) { > $old_name = $_; > eval $regexp; > die $@ if $@; > rename($old_name, $_) unless $old_name eq $_; > } > > exit(0);
This looks like a bad copy of Larry Wall's rename script, which used to be distributed with Perl. It's even lost its attribution. Here's the real thing: #!/usr/local/bin/perl -w # rename program by Larry Wall $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 $_; } -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]