hi John,
within SEC code, match variables are set in the following way:

@var = ($input =~ /regexp/)

This construct will assing the values for all ()-operators to the @var array. 
However, if there are no ()-operators in the matching regular expression, Perl 
will return the list ( 1 ), in order to indicate a match (an empty list is 
returned if there is a no match). That's why $1 is set to 1 in the case of 
match, even if there are no ()-operators in the regular expression. I 
acknowledge that this is a sort of idiosyncrasy, but implementing a special 
check for this case would make the match_regexp() routine much slower than it 
is now.
with kind regards,
risto

> From: John P. Rouillard <[email protected]>
> Subject: [Simple-evcorr-users] Problem with subpattern variable w/ wierd value
> To: [email protected]
> Date: Sunday, August 2, 2009, 5:05 AM
> Hi all:
> 
> I am running SEC 2.5.2 on Windows XP under cygwin 1.7 with
> perl
> revision 5 version 10 subversion 0 patch 34065 and I have
> another
> little conundrum with SEC.
> 
> Using the following ruleset:
> 
> # see what $1, $2, $3 evaluate to
> type = pair
> desc = subpattern test
> ptype= regexp
> desc2 = test subpattern
> pattern = test ([0-9]) ([0-9]) ([0-9])
> action = write - "$1, $2, $3, %1, %2, %3"; write -
> "dollar0: $0"; write - "pct0: %0"
> ptype2 = regexp
> pattern2 = test $2
> action2 = write - "%1, %2, %3, $1, $2, $3"; write -
> "dollar0: $0"; write - "pct0: %0"
> 
> with the input:
> 
>   test 7 8 9
>   test 8
> 
> I expect to see:
> 
>   Writing event '"7, 8, 9, %1, %2, %3"' to file -
>   "7, 8, 9, %1, %2, %3"
>   Writing event '"dollar0: test 7 8 9"' to file -
>   "dollar0: test 7 8 9"
>   Writing event '"pct0: %0"' to file -
>   "pct0: %0"
>   test 8
>   Writing event '"7, 8, 9, $1, $2, $3"' to file -
>   "7, 8, 9, $1, $2, $3"
>   Writing event '"dollar0: test 8"' to file -
>   "dollar0: test 8"
>   Writing event '"pct0: test 7 8 9"' to file -
>   "pct0: test 7 8 9"
> 
> but I actually see:
> 
>   Writing event '"7, 8, 9, %1, %2, %3"' to file -
>   "7, 8, 9, %1, %2, %3"
>   Writing event '"dollar0: test 7 8 9"' to file -
>   "dollar0: test 7 8 9"
>   Writing event '"pct0: %0"' to file -
>   "pct0: %0"
>   test 8
>   Writing event '"7, 8, 9, 1, $2, $3"' to file -
>   "7, 8, 9, 1, $2, $3"
>             ^ huh???
>   Writing event '"dollar0: test 8"' to file -
>   "dollar0: test 8"
>   Writing event '"pct0: test 7 8 9"' to file -
>   "pct0: test 7 8 9"
> 
> Why is $1 being replaced with 1 in the output? IIRC all the
> $n
> variables should be undefined if pattern2 doesn't have any
> subpatterns.  Also $1 should never have the value of 1
> in my senario.
> 
> So what command line parameter am I missing this time 8-)?
> Maybe -dont_play_games_with_john_he_has_only_had_1_coffee.
> 
> If I change pattern2 to capture a subpattern, the captured
> subpattern
> is properly displayed for $1.
> 
> Can anybody duplicate this on another platform?
> 
> Thanks.
> 
> --
>            
>     -- rouilj
> John Rouillard
> ===========================================================================
> My employers don't acknowledge my existence much less my
> opinions.
> 
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal
> Reports 2008 30-Day 
> trial. Simplify your report design, integration and
> deployment - and focus on 
> what you do best, core application coding. Discover what's
> new with 
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Simple-evcorr-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/simple-evcorr-users
>



      

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Simple-evcorr-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/simple-evcorr-users

Reply via email to