18.9.23 $|
Match or return a literal $| LHS and RHS operator
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 and 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 whether 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 (withth e $1) and a separator (the $|). Lastly, the RHS looks up the
username in a hypothetical badusers 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 ?§7.1.1 on page 252. 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.
This is the Title of the Book, eMatter Edition
Copyright ?© 2007 O??™Reilly & Associates, Inc.
Pages:
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200