[vox-tech] perl rename

Wes Hardaker wjhns156 at hardakers.net
Fri Sep 4 07:41:16 PDT 2015


"Brian E. Lavender" <brian at brie.com> writes:

> Shell command that does the following.
>
> rename "s/^/foo/" *.txt

I think I posted it a long time ago.  It was written before the command
line rename program existed, so there wasn't a conflict.

#!/usr/bin/perl

($op = shift) || die "Usage: rename expr [files]]\n";

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

for (@ARGV)
  {
  $was = $_;
  eval $op;
  die $@ if $@;

  if ($was ne $_)
    {
    print "rename($was,$_)\n";
    rename($was,$_);
    }
  }

exit;

-- 
Wes Hardaker                                     
My Pictures:       http://capturedonearth.com/
My Thoughts:       http://pontifications.hardakers.net/


More information about the vox-tech mailing list