Functions
[% bold = sub(text) { "<b>$text</b>" } # explicit braces bold = sub(text) "<b>$text</b>" # same thing as above - no braces bold(text) = "<b>$text</b>" # same thing as above - syntactic sugar %] [% bold('Hello World') %] --EOF--look inside...
Thus Spake Andy:
The sub
command can also be used to create anonymous subroutines as
part of an expression. In the first two lines we create an anonymous
subroutine and assign it to the bold
variable. The end result is
exactly the same as the code on the previous slide. The third line
shows a bit a syntactic sugar that allows you define a function by
putting the parens on the left side of the assignment operator. It gives
us a very simple, lightweight syntax for defining macro-like functions.
No more explicit MACRO
directive required!