[vox-tech] perl rename

Brian E. Lavender brian at brie.com
Fri Sep 4 14:35:58 PDT 2015


Excellent. Thanks. 

brian

On Fri, Sep 04, 2015 at 07:41:16AM -0700, Wes Hardaker wrote:
> "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/

-- 
Brian Lavender
http://www.brie.com/brian/

"There are two ways of constructing a software design. One way is to
make it so simple that there are obviously no deficiencies. And the other
way is to make it so complicated that there are no obvious deficiencies."

Professor C. A. R. Hoare
The 1980 Turing award lecture


More information about the vox-tech mailing list