procmail
[Top] [All Lists]

Re: simple multiplication using scoring

2010-02-06 06:04:30
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


So, then, with Ruud's help, this is quite simple. :-)
To get ab := a * b

john(_at_)system76-pc:~/procmail$ cat mult.rc
VERBOSE=yes
a=11
b=12
  dot = '.'
  :0
  *$  dot ??  $a ^ 1 < $b
  { } ab = "$="
john(_at_)system76-pc:~/procmail$ :|procmail -m mult.rc
procmail: [29607] Sat Feb  6 05:58:36 2010
procmail: Assigning "a=11"
procmail: Assigning "b=12"
procmail: Assigning "dot=."
procmail: Score:     132     132 "< 12"
procmail: Assigning "ab=132"

Thanx Ruud ! :-)
-- 
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>
  • Re: simple multiplication using scoring, John Simpson <=