David Gilden wrote:
> 
> Greetings,

Hello,

> I want to do the result of a substitution to $newname,
> but do not have it correct.
> 
> #!/usr/bin/perl

use warnings;
use strict;


> # rename from the Terminal OSX
> 
> $orig = "tina-o1.jpg";
> 
> ($orig = $newname)  =~ s/tina/quest/ig;

You are assigning $newname which is undef to $orig and then performing
the substitution on $orig.  You need to reverse the assignment and
assign $orig to $newname for that to work correctly.


> print $newname;
> 
>  __END__
> 
>  Then I would like to run from the command line the following:
>  (OSX flie re-namer)

You may already have a rename command.  To find out use which:

which rename


>  my @files = <>;

Reading a list from <> implies that each member of the list will have a
trailing newline.

chomp( my @files = <> );


> @files = sort @files;

Do you really need to sort?


>  foreach(@files){
>     my $newname;
>  ( $newname = $_)  =~ s/PIC1000/NEWNAME/;

You should verify that the new file name does not already exist or you
will overwrite that file.

if ( -e $newname ) {
    warn "Cannot rename $_ to $newname, it already exists.\n";
    next;
    }


> rename($_, "$newname");

You should verify that rename was successful.

rename $_, $newname or warn "Cannot rename $_: $!";


> }



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to