hdb has asked for the wisdom of the Perl Monks concerning the following question:
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...)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unexpected matching results
by dave_the_m (Monsignor) on Sep 06, 2013 at 07:45 UTC | |
by hdb (Monsignor) on Sep 06, 2013 at 07:51 UTC | |
|
Re: Unexpected matching results
by kcott (Archbishop) on Sep 06, 2013 at 07:58 UTC | |
by hdb (Monsignor) on Sep 06, 2013 at 08:29 UTC | |
|
Re: Unexpected matching results (dynamic scope "$1")
by Anonymous Monk on Sep 06, 2013 at 07:37 UTC | |
by hdb (Monsignor) on Sep 06, 2013 at 07:50 UTC |