2.8. Expressions
2.8.1. Introduction
Expressions are used in several places within SDF including:
- attribute values
- macro argument values
- filter parameter values
- evaluation within paragraph text.
The value of an expression can be placed into a paragraph by delimiting it with the special symbols [[ and ]]. For example:
The current file is [[DOC_FILE]].
2.8.2. Types of expressions
An expression is either:
If an expression is a single word, it is the value of a variable. Otherwise, it is evaluated as a Perl expression. A Perl expression is typically one of the following:
- a numeric literal (e.g.
213 ) - a string literal (e.g.
"User Guide" ) - a subroutine call (e.g.
length("User Guide") ).
2.8.3. Accessing variables within Perl expressions
Within a Perl expression, SDF variables are available via the var associative array. The syntax used by Perl for accessing a value within an associative array is:
"$" array_name "{" string_index "}"
Some examples are:
- get the length of the DOC_AUTHOR variable:
length($var{'DOC_AUTHOR'})
- concatenate the document name and type:
"$var{'DOC_NAME'} $var{'DOC_TYPE'}"