Vladimir Lemberg wrote: > Hi, Hello,
> I have a script, which suppose to find all *.xml files under the specified > directory then process them. I'm facing the pattern match problem: > > use strict; > use warnings; > use Win32; > use File::Find; > > @ARGV = Win32::GetCwd() unless @ARGV; Why are you storing the scalar value returned from GetCwd() into the array @ARGV? > my @dirs; > > find (\&FindXml, $ARGV[0]); find( \&FindXml, Win32::GetCwd() ); Or: my $cwd = Win32::GetCwd(); find( \&FindXml, $cwd ); > sub FindXml > { > return if !stat || -d; You are stat()ing the same file twice when you only have to stat() it once: return if !stat || -d _; Or just: return if -d; > ( my $xml_file = $File::Find::name ) =~ /^.+\.xml$/; > push ( @dirs, $xml_file ); > } > > In this examples the pattern match /^.+\.xml$/ is not working and all files > regardless of the extension have been assigned to $xml_file variable. That is because even though you are using a regular expression you are not basing the decision on whether or not to add the file name to the array on the result. You should only add the file name to the array if it matched the regular expression and not add it if it didn't match. push @dirs, $File::Find::name if /\.xml$/; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/