foreach my $f ( @files ){ # Iterate through the @files array, foreach iteration set the value of $f to the next element of @files
if( $f =~ /private/ ){ next; } # If the scalar $f contains the text "private", then stop this iteration and move onto the next one chomp $f; # Remove the newline character(s) from the $f scalar if present $fil{$f} = 0; # Create or set the value of $f in the hash %fil to 0 # if we match the extension... if( $f =~ /\.$extension$/ ){ # If there is a matching extension after the last . in the value of $f } # if this isn't a directory name... if( $f !~ /\\$/ ){ delete( $fil{$f} ); } # This should not work. (At least under Win32). Directory names do not include the \ # This code is checking for a \ at the end of the scalar value. e.g test\ } You could rewrite to look like this foreach ( @files ){ # Use the special $_ var to store each iteration next if /private/i; # Stop this iteration if the value of $_ contains private, case insensitive chomp; # Chomp defaults to $_ if not specified. $fil{$f} = 0; # if we match the extension... if(/\.$extension$/){ # You need to add some code here... } # if this IS a directory - Surely you only want your list of files to consist of file, not dirs?? - remove the entry from the %fil hash if(-d $_) delete( $fil{$_} ); } HTH John -----Original Message----- From: Bruce Ambraal [mailto:[EMAIL PROTECTED]] Sent: 13 February 2002 13:36 To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Perl regular expresions HELP! Please explain to me what this code does, here I'm tying to rename files in current directory to 1.fil, 2.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} ); } } The complete program is: ------------------------------------------------ #!/usr/local/bin/perl -w # first example... use strict; # declarations... my @files = `ls -F`; 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} ); } } 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, ... PLEASE HELP!!! THANK! Bruce -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------Confidentiality--------------------------. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]