FOREACH MODULE - foreach.pm
The foreach module implements a simple foreach loop. Its file name is foreach.pm.

The foreach loop is similar in functionality to that of other programming languages such as Perl. It takes a list of values separated by a user definable delimiter (',' by default). It then iterates through all values in the list, defining a macro to be each individual value for each iteration of the loop. The loop terminates when all values have been used.

The foreach module implements the following keywords:

#foreach macro list
    The #foreach keyword is functionally equivalent to the following Perl style loop: foreach macro (split(/delim/, list)) The #foreach keyword requires the following space separated parameters: macro : The name of the macro to which the foreach loop should assign the current list value. list : The list of values, separated by delim (see #foreachdelim keyword for how to set delim). list can also be a macro or contain macros. The loop will run from the #foreach keyword to the next #endforeach keyword.

#endforeach
    The #endforeach keyword is used to signify the end of the loop. Everything within the opening #foreach and the closing #endforeach will be processed on each iteration of the loop.

Example usage: #foreach VALUE one, two, three, four
  VALUE #endforeach In the above example VALUE will be defined to have values one, two, three and four for each successive iteration through the loop. Nested loops are also possible.

#foreachdelim /delim/
    The #foreachdelim keyword is used to set the delimiter used in each list. The delimiter can be any character, string or regular expression. The delimiter should be enclosed in forward slashes, in the same style as Perl regular expressions. The default value for delim is ','. To set the delimiter to be a single space do: #foreachdelim / / To set delim to be any amount of white space do: #foreachdelim /\s+/ See the Perl documentation on regular expressions for more advanced uses.