hi Bond,
is my understanding correct that you would like to match a one-line comma
separated list of strings and generate a separate synthetic event for each
list element? In other words, if the input is
aaa,bbb,ccc,ddd
your action should produce the following four events:
aaa
bbb
ccc
ddd
The above problem can be addressed in a much simpler way, and here is an
example which does that with just two actions:
type=Single
ptype=regexp
pattern=list: (.+)
desc=take a comma separated list and generate events for list elements
action=lcall %events $1 -> ( sub { split(/,/, $_[0]) } ); \
event %events
The 'lcall' action will split the input string into parts by comma, and the
elements will be returned not as a scalar, but rather as a list. When a
list value is returned from 'lcall', it is stored as a multiline string
into %events variable. After that, the 'event' action is invoked for the
%events variable. However, when 'event' action is applied against multiline
string, it generates a separate synthetic event for each line in the string.
The SEC 'while' and 'if' actions are handy for a number of advanced tasks
(e.g., looping over context event stores, sending multiple udp packets to
remote destinations, etc.) , but here you don't really need them, since
everything can be handled with simpler actions in a much shorter way. Also,
apart from the 'event' action, the SEC context actions have a similar
support for multiline strings (please see the official docs for more
detailed information).
kind regards,
risto
2015-10-05 6:52 GMT+03:00 Bond Masuda <[email protected]>:
> I need to process a comma delimited list and generate an internal event
> for each item. Below is what i have for my action list, but I don't know
> if this is the best way to accomplish what I'm doing:
>
>
>
> action= assign %list $1; \
> assign %i 0; \
> assign %have_item 1; \
> while %have_item ( \
> eval %list_item ( \
> my $i = %i; \
> my @list = split(/,/,"%list"); \
> return $list[$i]; \
> ); \
> event 0 PROCESS_ITEM %list_item; \
> eval %i ( my $i = %i; return $i++; ); \
> eval %have_item ( \
> my $i = %i; \
> my @list = split(/,/,"%list"); \
> if( $i < scalar(@list) ){ \
> return 1; \
> }else{ \
> return 0; \
> } \
> ); \
> )
>
> The interaction between my loop control variables in the SEC context
> versus in the perl mini-programs in 'eval' seem cumbersome. Is there a
> better way to do this?
>
> Also, is it correct to initialize my while loop control %have_item
> before starting the while loop? Or is that not necessary? There is an
> assumption here that $1 is not an empty list, and that should be ok as
> there is a check before this rule and this rule will not trigger unless
> the list is not empty.
>
> Thanks,
> Bond
>
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Simple-evcorr-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/simple-evcorr-users
>
------------------------------------------------------------------------------
_______________________________________________
Simple-evcorr-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/simple-evcorr-users