While trying to come up with an elegant solution to File Parsing and Pattern Matching I am completely stuck on something I have no explanation for. Here is the solution I came up with:
use strict; use warnings; use Data::Dumper; my %results = do { local $/ = ''; # paragraph mode map { /TYPE (\S+)/ => { 'cause' => (/CAUSE (\S+)/ ?$1:'UNDEF'), 'effect' => (/AFFECT (\S+)/?$1:'UNDEF'), } } <DATA>; }; print Dumper \%results; __DATA__ TYPE VALUE1 EQUALS MAIN CAUSE FAIL AFFECT ERROR ENDTYPE
shortening Mark.Allan's data to illustrate the point. While I am unable to spot any flaws in my logic it prints the following:
$VAR1 = { 'VALUE1' => { 'effect' => 'ERROR', 'cause' => 'ERROR' # instead of 'FAIL' } };
If I change the order of 'cause' and 'effect' in the code above I get 'FAIL' twice.
How can this be? And how can it be fixed? (Must be a case of Perl punishing my vanity...)
In reply to Unexpected matching results by hdb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |