X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FFilter.pm;h=aefa922419ee94afac488101b11c184aba45a8eb;hb=9e2fbafcfdab1ee45e581524311f1a97ac41f6ad;hp=4f1f4e5336d51228d9c1b266f054a3b1d1344cf7;hpb=c53f72111659792f75dd5040b7ee27e729f1ed78;p=spider.git diff --git a/perl/Filter.pm b/perl/Filter.pm index 4f1f4e53..aefa9224 100644 --- a/perl/Filter.pm +++ b/perl/Filter.pm @@ -23,7 +23,7 @@ # # # @in = ( -# [ action, fieldno, fieldsort, comparison ], +# [ action, fieldno, fieldsort, comparison, action data ], # ... # ); # @@ -37,7 +37,8 @@ # numeric, 'r' is ranges of pairs of numeric values and 'd' is default. # # Filter::it basically goes thru the list of comparisons from top to -# bottom and when one matches it will return the action. The fields +# bottom and when one matches it will return the action and the action data as a list. +# The fields # are the element nos of the list that is presented to Filter::it. Element # 0 is the first field of the list. # @@ -69,27 +70,30 @@ sub init sub it { my $filter = shift; + my ($action, $field, $fieldsort, $comp, $actiondata); my $ref; # default action is 1 - return 1 if !$filter; - + $action = 1; + $actiondata = ""; + return ($action, $actiondata) if !$filter; + for $ref (@{$filter}) { - my ($action, $field, $fieldsort, $comp) = @{$ref}; + ($action, $field, $fieldsort, $comp, $actiondata) = @{$ref}; if ($fieldsort eq 'n') { my $val = $_[$field]; - return $action if grep $_ == $val, @{$comp}; + return ($action, $actiondata) if grep $_ == $val, @{$comp}; } elsif ($fieldsort eq 'r') { my $val = $_[$field]; my $i; my @range = @{$comp}; for ($i = 0; $i < @range; $i += 2) { - return $action if $val >= $range[$i] && $val <= $range[$i+1]; + return ($action, $actiondata) if $val >= $range[$i] && $val <= $range[$i+1]; } } elsif ($fieldsort eq 'a') { - return $action if $_[$field] =~ m{$comp}; + return ($action, $actiondata) if $_[$field] =~ m{$comp}; } else { - return $action; # the default action + return ($action, $actiondata); # the default action } } } @@ -102,9 +106,20 @@ sub it # sub read_in { - my ($sort, $call) = @_; - my $fn = "$filterbasefn/$sort/$call.pl"; + my ($sort, $call, $flag) = @_; + + # first uppercase + $flag = ($flag) ? "in_" : ""; + $call = uc $call; + my $fn = "$filterbasefn/$sort/$flag$call.pl"; + + # otherwise lowercase + unless (-e $fn) { + $call = lc $call; + $fn = "$filterbasefn/$sort/$flag$call.pl"; + } + # load it if (-e $fn) { do "$fn"; dbg('conn', "$@") if $@; @@ -133,7 +148,8 @@ sub write_out } my $today = localtime; - print FILTER "# + print FILTER "#!/usr/bin/perl +# # Filter for $call stored $today # \$in = [ @@ -141,7 +157,7 @@ sub write_out my $ref; for $ref (@_) { - my ($action, $field, $fieldsort, $comp) = @{$ref}; + my ($action, $field, $fieldsort, $comp, $actiondata) = @{$ref}; print FILTER "\t[ $action, $field, $fieldsort,"; if ($fieldsort eq 'n' || $fieldsort eq 'r') { print FILTER "[ ", join (',', $comp), " ],";