[perl sub] subname arg [/perl]
construct. Use the ``here document'' capability of MiniVend configuration
files to make it easy to define:
Sub <<EOF
sub sort_cart { my(%items) = @_; my($item,$name); my $out = '<TABLE BORDER=1>'; foreach $name (sort keys %items) { $out .= '<TR><TD>'; $out .= $items{$name}; $out .= '</TD><TD>'; $out .= $name; $out .= '</TD></TR>'; } $out .= '</TABLE>'; return $out; } EOF
As with Perl ``here documents'', the EOF (or other end marker) must be the ONLY thing on the line, with no leading or trailing white space. Do not append a semicolon to the marker.
The above would be called with:
[perl sub] sort_cart ( [item-list] "[item-description]", "[item-code]", [/item-list] ) [/perl]
and will display an
HTML table of the items in the current shopping cart,
sorted by the description. (Using an alternative form of quoting such as q{
} will minimize problems with quotes in the passed parameters -- you may
use any style you like, including here documents. Syntax errors will be
reported to error.log
.)
Catalog subroutines may not perform unsafe operations -- the Safe.pm module enforces this.