Eurospace Szarindar wrote: > > > De: Tomas Corral [mailto:[EMAIL PROTECTED] > > > > Because '@' is a special character for many interpreters. I'm > > trying to > > change the names of 100 files deleting the '@' symbol. The filenames > > look like this: > > > > [EMAIL PROTECTED] > > [EMAIL PROTECTED] > > [EMAIL PROTECTED] > > [EMAIL PROTECTED] > > [EMAIL PROTECTED] > > .... > > Try this little and simple script : > > #!/usr/bin/perl -w > use strict; > > open 'fh' ,'ls ./[EMAIL PROTECTED] |'; # create a file handle
You should *ALWAYS* verify that open() succeeded and since you are forking a separate process you should verify that close() succeeded as well. But you don't need to run a separate process to do something that you can do directly in perl with opendir/readdir/closedir or glob. > my @file_list = (<fh>); ^ ^ There is only one operator so using parentheses to set precedence is superfluous. > scalar (@file_list) or die "There is no file to change"; > > chomp(@file_list); > > foreach my $file (@file_list) { > print "renaming ". $file; > my $new_file = $file; > $new_file =~ s/@/_ad_/; # change @ to '_ad_' > $new_file =~ s/=/_equal_/; > print " to ".$new_file." ... "; > rename ($file, $new_file) ? print "OK \n" : print "NOK error_n on > $file, $new_file \n"; You should include the $! variable in the error message so you know why it failed. > } > > close 'fh'; 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>