Vladimir Lemberg am Montag, 12. Februar 2007 21:33:
> Hi,
Hi Vladimir
(in addition to Davids post)
> 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
The pattern match _is_ working, but the effekt is not the desired one :-)
In this line, you first assign (unconditionally) $File::Find::name to
$xml_file. Then a match is tried, giving a true or false result that is
_not_used_. That's the reason why:
> all files
> regardless of the extension have been assigned to $xml_file variable.
>
> #################
>
> However, if I change parenthesis to count the matching, the pattern seems
> to work.
>
> sub FindXml
> {
> return if !stat || -d;
> my $xml_file = ( $File::Find::name =~ /^.+\.xml$/ );
> print $xml_file;
> }
Here, $xml_file will have a boolean value, despite of the variable name.
Hope this explanation is useful (and correct),
Dani
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/