R p wrote: > > hi all Hello,
> i am a beginner and i need some help from you: > here is my problem: > ------------------------------------------------------ > i have to filter all files *.BMP and to rename all by > *.bmp > ------------------------------------------------------ > here is my script: > ------------------------------------------------------- > #!/usr/bin/perl ^^^ The first two characters of a script HAVE to be '#!' so the operating system will recognise it as a script. > open(BMP, "find . -type f | grep .BMP |"); You should ALWAYS verify that the pipe opened successfully. open(BMP, "find . -type f | grep .BMP |") or die "Cannot open pipe to 'find . -type f | grep .BMP |' $!"; > foreach (<BMP>) { foreach will read the entire file into memory before processing it, you should use a while loop instead. while ( <BMP> ) { > chop; You should use chomp instead of chop. > /(.*)\.BMP/; > print "processing image $_ ..\n"; > system("mv", $_, "$1.bmp"); You should verify that the regular expression matched before using the numeric variables. You should verify that system() was successful. chomp; if ( /(.*)\.BMP/ ) { print "processing image $_ ..\n"; system( 'mv', $_, "$1.bmp" ) == 0 or die "system 'mv $_' failed: $?"; } > } > print "Done."; > > close(BMP) You should ALWAYS verify that the pipe closed successfully. close BMP or die "Cannot close pipe to 'find . -type f | grep .BMP |' $!"; 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__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]