procmail
[Top] [All Lists]

Re: Help needed with a recipe

1997-11-07 12:45:24
Jari Aalto was wondering about these:

|              WSPACE = "    \n"      # whitespace = space, tab newline

No, just as procmail doesn't grok \t, it doesn't know from \n either.
To save a space, a tab, and a newline in a variable, you need to do this:

WSPACE="        ""
"

This might be easier to read, though:

WSPACE="        "'
'

|             *$ variable ?? [$WSPACE]

No good.  A bracketed range, whether negated or not, will *never* match a
newline.

A variable to save an expression that will match a space, a tab, or a newline
is this (to use your suggested variable names):

WSPC="( |       |$)"

To match a space or a tab, don't bother doing this:

SPTB="[         ]"

but rather this:

LWSP="  "

because if you leave the brackets out, you can negate it:

$       [$LWSP]
  matches a space or tab.

$       [^$LWSP]
  matches anything except a space, a tab, or a newline.

$      ([^$LWSP]|$)
  matches anything except a space or a tab, even a newline.

| Or should it say this sto get the correct effect?

|             *$ variable ?? [^$\WSPACE]

Don't use $\ inside brackets because the leading () generated by $\ will
trip you up.

| What if I want literal $ inside bracket?

A $ inside brackets, unless it begins a variable name and the "$" modifier
is on, *always* means a literal dollar sign.  It cannot mean a newline if
it appears inside brackets.  A good way to keep it exempt from "$" inter-
pretation is to put it last inside the brackets (unless you also need to
include a literal hyphen and you can't put the hyphen first; then you'll need
to escape the dollar sign with a backslash and put the hyphen last -- well,
you could alternatively escape the hyphen, I guess), because procmail knows
that "$]" cannot possibly be a reference to a variable.

General guideline:
  ($) always matches a newline, with or without "$" interpretation;
  [$] always matches a dollar sign, with or without "$" interpretation;

| Is the WSPC correct abbreviation for whitespace? 

It will be if that's what you decide on.

<Prev in Thread] Current Thread [Next in Thread>