Name
$|
Synopsis
It is sometimes necessary to communicate information between one rule
and another. The preferred way of doing this is to use the special
$| operator, which can be used in both the LHS or
RHS of rules. To illustrate, consider the following two rules:
R $- $: $1 $| $(badusers $1 $) R $- $| BAD $# discard $: discard
Here, the first rule’s LHS checks to see if there is
a single token in the workspace (as would be the case if it contained
a username). If that is the case, the RHS returns the original
workspace (with the $1) and a separator (the
$|). Lastly, the RHS looks up the username in a
hypothetical baduser database, and if the user is
found, the result of the lookup (either a literal GOOD or BAD, for
example) is appended to the workspace.
The second rule looks for a workspace that now contains the original
username (the $-), followed by a literal separator
(the $|) and the literal word BAD. If BAD is
found, that user’s email is discarded with the
discard delivery agent.
One actual example of using $| can be found in
Section 7.1.1. That section also describes a trick for
using $| in rule-testing mode. Note that the
$| operator can be used in either the LHS or RHS
of a
rule.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access