procmail
[Top] [All Lists]

Re: simple multiplication using scoring

2009-11-26 03:01:11
This still invokes a shell, but I'm pretty sure that it is faster than
fancy scoring ... based on LuKreme's experiment just a short while
ago.

[john(_at_)bx1]# H:~> cat test.rc
VERBOSE=yes
DNSBL_OVER=4
DNSBL_MULTIPLIER=150
DNSBL_TWO="12"
DNSBL_RESULT=`echo $((DNSBL_TWO*DNSBL_MULTIPLIER))`
:0
*$ -$DNSBL_OVER  ^0
*$  $DNSBL_RESULT^0
{ EXCESS=$= }
[john(_at_)bx1]# H:~> :|procmail -pm test.rc
procmail: [18266] Thu Nov 26 01:58:48 2009
procmail: Assigning "DNSBL_OVER=4"
procmail: Assigning "DNSBL_MULTIPLIER=150"
procmail: Assigning "DNSBL_TWO=12"
procmail: Executing "echo $((DNSBL_TWO*DNSBL_MULTIPLIER))"
procmail: Assigning "DNSBL_RESULT=1800"
procmail: Score:      -4      -4 ""
procmail: Score:    1800    1796 ""
procmail: Assigning "EXCESS=1796"


On 11/25/09, Professional Software Engineering
<PSE-L(_at_)mail(_dot_)professional(_dot_)org> wrote:
Someone has probably come across this in the past, but I didn't find a 
reference to it in my searching, so I thought I might throw this out there 
for anyone who might find this useful.

 I have a need to multiply two values within a procmail recipe.  Basically, 
one value which is set, and another which is determined as the number of 
matches BEYOND a threshold.  That is, where I'm using this, I'm not 
performing the match operation that results in a number of match events, so I 
can't simply use the multiplier with an exponent of 1.


 # figure there's some logic that gets DNSBL_OVER.  For test purposes,
 # let us assume it was evaluated to 4
 DNSBL_OVER=4

 # Set DNSBL_MULTIPLIER
 DNSBL_MULTIPLIER=150
 # string of exactly two characters
 DNSBL_TWO="12"

 :0
 * $ -$DNSBL_OVER^0
 * $ $DNSBL_OVER^$DNSBL_MULTIPLIER DNSBL_TWO ?? .
 {
         DNSBL_RESULT=$=
 }


 The logic here is that we first subtract the count (the weight), and then we 
match TWO characters, using the weight with the exponent (MULTIPLIER).  So:

 procmail: Score:      -4      -4 ""
 procmail: Score:     604     600 "."
 procmail: Assigning "DNSBL_RESULT=600"

 Certainly, if it were clean and easy, it'd be nice to match with 
multiplier^1 count times, but that wound necessitate creating something that 
would match the desired number of times, and if the count is high, it would 
also get ugly.

 Obviously, one still runs into maximal matching constraints associated with 
scoring (so, a signed 32 bit value).  Another liability is that because the 
score is being initialized with a negative, there are potential issues if the 
weight or exponent are themselves negative numbers.  Rather, everything is 
fine if the EXPONENT is a negative, but if the weight is, then there will be 
a syntax issue (as the variable is preceeded by a hyphen).

 This doesn't happen to be an issue for what I'm doing, but it is a notable 
issue for anyone wanting to do generic math.  My immediate needs are 
satisfied, but I'm curious whether anyone else here is doing signed 
multiplication using scoring.

 Yea, anything to avoid an unnecessary shell <g>
 ---
  Sean B. Straw / Professional Software Engineering

  Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
  Please DO NOT carbon me on list replies.  I'll get my copy from the list.

 ____________________________________________________________
 procmail mailing list   Procmail homepage: http://www.procmail.org/
 procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de
 http://mailman.rwth-aachen.de/mailman/listinfo/procmail




-- 
John Wesley Simpson
SwaJime's Cove℠
www.swajime.com

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail
<Prev in Thread] Current Thread [Next in Thread>