Rob Dixon wrote:

> Hi Scott.
> 
> Scott R. Godin wrote:
>> John W. Krahn wrote:
>>
>> >     chomp;
>> >     if ( /(.*)\.BMP/ ) {
>> >         print "processing image $_ ..\n";
>> >         system( 'mv', $_, "$1.bmp" ) == 0 or die "system 'mv $_'
>> > failed: $?";
>> >         }
>>
>> next unless /(.*)\.BMP$/;#anchor it to the end of the string!
>> print "processing image file: $_\n";
>>
>> #rename will clobber existing files, so check first!
>> warn "File exists!: $1.bmp. skipping...\n" && next
>>         if -f "$1.bmp";
>>
>> # use perl rather than spawning external processes!
>> rename( $_, "$1.bmp" ) or die "unable to rename file $_: $!";
> 
> There's a big [SNIP] here from the end of John's post:
> 
> John W. Krahn wrote:
>> However, you could write the whole thing in perl and avoid the pipes
>> and system().
>>
>> #!/usr/bin/perl
>> use warnings;
>> use strict;
>> use File::Find;
>> use File::Copy;
>>
>> find( sub {
>>     return unless -f and /^(.+)\.BMP$/s;
>>     move( $_, "$1.bmp" ) or warn "Cannot move $_: $!";
>>     }, '.' );
>>
>> __END__
> 
> Rob

Yes,. I saw his post after I posted mine. 

However, this still doesn't address the issue of clobbering existing files 
(File::Copy documentation makes no mention of this issue). MY whole issue 
was not using external 'mv' when perl already has 'rename', and the 
possible issue of overwriting files that already exist. 

It IS, however, yet another way of doing things (which Perl is well known 
for)

to select the files, I'd have done a chdir to the directory in question, and 
then a (my @files = glob "*.BMP";) myself.

File::Find is another perfectly good way of accomplishing this in a 
different way. It all depends on your approach. EITHER way is perfectly 
viable, but you STILL have to address the potential issue of overwriting 
existing files on a case-sensitive filesystem. 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to