procmail
[Top] [All Lists]

Re: exactly once

2004-08-23 05:43:04
On Sun, Aug 22, 2004 at 09:27:12PM -0500, David W. Tamkin wrote:

On newsgroup comp.mail.misc -- except for Alan Clifford, I don't know 
who else here reads it -- someone asked how to test that the exit code 
of a program is exactly 1 ... not 0, not 2 or more.  Besides straight-
forward but boring things like these:

 [snipped]


I thought of this, and in testing, it worked for all values from 0 to 
255, failing for 0 and for 2 through 255 but matching for 1:

 :0
 * 1^-.5 ! ? command
 * -.8^0
 action

It could be extended to testing whether a pattern appears exactly once:

 :0
 * 1^-.5 regexp
 * -.8^0
 action

Now if only that could be generalized to testing for numbers of 
occurrences (or for exit codes) other than 1.

It does look promising.  Bravo!  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.

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

(I haven't tested this specific code right now.)

Dallman

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