procmail
[Top] [All Lists]

Re: Getting partial matches from a string without forking an outside process

2005-01-08 18:52:12
Toen wij Dallman Ross kietelden, kwam er dit uit:
Ruud H.G. van Tol:

AFAIS, that is basically the same solution. But with a run of
x's you can't split another string. :)

Yeah, but you were bothering to save the right-hand string,
and then were iterating to create the number of dots, and
then matching the dots against the start of the string.

The quest was to split up a random string in a head and a tail. 

Alternative:
     :0
     *$ var ?? $\var_Head\/.*
     { var_Tail = "$MATCH" }


I don't see any need to save the right-hand part.  What for?
And as long as we're iterating, let's just accrete letters
from the left instead of making dots.

Well, that depends on the situation, whether that is sufficient.


Btw, we don't even need $LEN in mine.  Here it is even shorter:

########## start main.rc ##########
 :0
 *       1^1 FOO ?? .
 *       1^0
 * $ -$LOP^0
 { INCLUDERC = lop.rc }

 FOO = "$BAR"

########### start lop.rc ##########
 :0
 * $ $=^0
 *   -1^0  FOO ?? ^^\/.
 { BAR = "$BAR$MATCH"   SWITCHRC = $_ }


The  -1^0  FOO ?? ^^\/. always only uses the first letter of FOO.
Let's make it also work when FOO = 'abcdefghijklmnopqrstuvwxyz'.

  :0
  * RUNMODE ?? ^^()^^
  {
#VERBOSE=on
    FOO = "${FOO:-abcdefghijklmnopqrstuvwxyz}"
    LOP = "${LOP:-9}"
    :0
    *      1^1 FOO ?? .
    *$ -$LOP^0
    { LEN="$="
#VERBOSE=off
      BAR  RUNMODE='R'  INCLUDERC="$_"  RUNMODE
#VERBOSE=on
      :0
      *$ FOO ?? ^^$\BAR\/.*
      { FOO="$BAR"  BAR="$MATCH" }
    }
  }
  :0E
  *  RUNMODE ?? ^^R^^
  *$      -$LEN^0
  *  2147483647^0
  *           1^1  FOO ?? ()\/.
  { BAR="$MATCH$BAR"
    :0
    *$ $LEN^0
    *    -1^0
    { LEN="$=" SWITCHRC="$_" }
  }

-- 
Grtz, Ruud

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