Hi all,
I'm parsing a logfile and don't quite understand the behaviour of m//.
From a previous regex match I have already captured $+{'GFP'}:
use strict;
use warnings;
(...)
$text =~ m/ (?<GFP>FILTERS .*? WRT)/x; # I simply have my whole
logfile in $text - I know there are better solutions.
print $+{'GFP'}, "\n";
prints this:
FILTERS GFP,GFP,100% ACTSHUT 17 AVG 4,1.000000 WRT
Now I want to go on parsing $+{'GFP'}. To be more precise, I want to
capture "AVG 4":
If I do:
$+{'GFP'} =~ m/(?<AVG>AVG\s\d);
print "\$+{'GFP'} is $+{'GFP'}.\n";
I get a warning that I'm using an uninitialised value and:
$+{'GFP'} is .
$+{'AVG'} is AVG 4.
So first question: Apparently some return value of $+{'GFP'} =~
m/PATTERN/; messes with this hash value. So from what I can remember,
the return value will indicate if the substitution was successful or
not. Then why don't I get some value like 0 or 1 in $+{'GFP'} but just
an uninitialised value?
If the match is not successful, $+{'GFP'} will stay untouched:
$+{'GFP'} =~ m/(?<AVG>AVG\s\d nothere);
print "\$+{'GFP'} is $+{'GFP'}.\n";
print "\$+{'AVG'} is $+{'AVG'}.\n";
will print:
$+{'GFP'} is FILTERS GFP,GFP,100% ACTSHUT 17 AVG 4,1.000000 WRT.
$+{'AVG'} is .
Not surprisingly, $+{'AVG'} is uninitialised here.
It didn't quite make sense to me but I figured that the problem might be
that m// in list context returns a list of the capture variables created
in the match. So I tried:
$+{'GFP'} =~ scalar m/(?<AVG>AVG\s\d)/;
print "\$+{'GFP'} is $+{'GFP'}.\n";
print "\$+{'AVG'} is $+{'AVG'}.\n";
prints this:
$+{'GFP'} is FILTERS GFP,GFP,100% ACTSHUT 17 AVG 4,1.000000 WRT.
$+{'AVG'} is .
So now the match suddenly fails?!?
I'm confused.
Many thanks for your help.
Florian
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/