On 02/12/2007 02:33 PM, Vladimir Lemberg wrote:
Hi,
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;
my @dirs;
find (\&FindXml, $ARGV[0]);
sub FindXml
{
return if !stat || -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.
[...]
You probably want to push the filename onto the array if you get a
successful match:
sub FindXml
{
return if !stat || -d;
( my $xml_file = $File::Find::name ) =~ /^(.+\.xml)$/;
push ( @dirs, $xml_file ) if $1;
}
This would be a simpler way to do it:
sub FindXml {
return if !stat || -d;
push @dirs, $File::Find::name if /^.+\.xml$/;
}
HTH
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/