I have a hash with some key/value pairs
my %hash = ('key1','value1', 'key2', 'value2');
I pass it in the Stash to use it in a html template:
$c->stash( theHash => %hash);
And then, in the Template, to display the values I think I should use something like
[% theHash.key1 %] #It should display "value1"
[% theHash.key2 %] #It should display "value2"
But it does not work.
It works if I pass values one by one:
$c->stash( valueOfHash1 => $hash{'key1'});
$c->stash( valueOfHash2 => $hash{'key2'});
And retrieving it as
[% valueOfHash1 %] #It displays "value1"
[% valueOfHash2 %] #It displays "value2"
But the hash will have a lot of values. It does one seems to be a good idea.
What I am missing? Thank you in advance.
If you drop a hash into list context, it gets unrolled into a list.
You want to store a hash reference.