procmail
[Top] [All Lists]

Re: exactly once

2004-08-23 07:29:24
Dallman Ross wrote:

However, I'd like to see it
tested cross-platform on different builds.  That is because we had
found two years ago that there are some, shall we say, anomalies
in procmail's results shown for decimal weights (at least for the
"x" value).  I've saved the thread somewhere, but it is also
easily found in the archives.

Hmm.  Oh well.

Fwiw, another approach for testing "just one" is to use the
"Infinity Shuffle":

   INFINITY = 2147483647  # don't pad this one

   :0
   *             1^0
   *    -$INFINITY^0
   *           -1^-1 ! ? command
   # Are we still here?  Good: didn't happen more than once
   * $   $INFINITY^0
   action

Sorry, I don't see that. It looks to me that if the exit code of the command is 0, 2, or any other even number, the condition will score 0, the recipe will score 1, and the action will be run; if the exit code of the command is odd the condition will score -1, the recipe will abort with a score of -2147483647, and the action will be skipped. So if the command's exit code is 1 or any even number (including 0), we'll get a wrong result. It will come out right only if the exit code of the command is an odd number from 3 through 255. If we flip the logic,

    INFINITY = 2147483647  # don't pad this one

    :0
    *             1^0
    *    -$INFINITY^0
    *           -1^-1 ! ? command
    # Are we still here?  Good: didn't happen more than once
    * $   $INFINITY^0
    { }
    :0E
    action

then it will be right for all even values and for 1; if the command's exit code is always 0, 1, or 2 and never 3 or higher, then it will work.

But then it's just a hard way to write,

 :0 # perform action if exit status is odd
 * 1^-1 ! ? command
 action

Your infinity shuffle is great for testing for a maximum or minimum number of occurrences (or a maximum or minimum exit code from a ? condition); this time we have a single desirable value surrounded by undesirable ones.


____________________________________________________________
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>