Bruce Ambraal wrote: > > Please explain to me what this code does, here I'm tying to rename files > in current directory to 1.fil, 2.fil, ... > > [snip code] > > The complete program is: > ------------------------------------------------ > #!/usr/local/bin/perl -w > # first example... > > use strict; > > # declarations... > my @files = `ls -F`;
There is no good reason to run an external program to get the files from the current directory. my @files = glob '*'; # or my @files = <*>; # or opendir DIR, '.' or die "Cannot open dir '.': $!"; my @files = readdir DIR; closedir DIR; > my %fil; > foreach my $f ( @files ){ > if( $f =~ /private/ ){ next; } > chomp $f; > $fil{$f} = 0; > # if we match the extension... > if( $f =~ /\.$extension$/ ){ > } > # if this isn't a directory name... > if( $f !~ /\\$/ ){ delete( $fil{$f} ); } If you want to test if a file name is a directory you can use the -d function. delete $fil{$f} if -d $f; > } > > Would some luv some assistance. > > The struggling part is after having read current dir > file into an array, I now want to rename these files > into current dir to 1.fill, 2.fill, ... #!/usr/local/bin/perl -w # first example... use strict; my $counter = 0; my $extension = 'something'; for my $file ( glob '*' ) { next if -d $file or $file =~ /private/; next unless $file =~ /\Q.$extension\E$/; $counter++ while -e "$counter.fill"; rename $file, "$counter.fill" or die "Cannot rename $file to $counter.fill: $!"; } __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]