How do you access variables in a hash when using Perl’s HTML::Template module?
I’m building the following hash in my Perl code:
# Load success/error flash messages
if ($query->param("submit")) {
$template->param(
FLASH => {
CLASS => "success",
MESSAGE => "Your cart has been successfully updated!"
}
);
}
I’d like to access these variables in my template. To access a regular variable, you do:
<TMPL_VAR NAME=FLASH>
How might I access FLASH[‘CLASS’] in my template?
There’s nothing in the documentation that indicates you can set a parameter as a hashref. The closest to what you want to do is to put the hashref in an arrayref:
Then you can access it as:
But having an array with a single element might be overkill. An alternative is to get rid of the hashref and flatten the structure: