feiiiiiiiiiii has asked for the wisdom of the Perl Monks concerning the following question:
Hi guys,
I'm using Template module for web programming. Everything works fine, except the keys and values keywords for hashes were not working as expected.
The variable I passed in is as below when dump print:
my $VARS = { 'rows' => { 'category1' => [ {'id' => 'AAA', 'delta' => '0.01%'}, {'id' => 'BBB', 'delta' => '0.03%'} ], 'category2' => [ {'id' => 'CCC', 'delta' => '0.02%'}, {'id' => 'DDD', 'delta' => '0.04%'} ], }, };
(The actual variable is much more complicated. I simplified it as above)
The code below works perfectly:
[% FOREACH item IN report.rows.category1 %] <tr> <td>[% item.id %]</td> <td>[% item.delta %] %</td> </tr> [% END %]
But the code below does not produce any entries:
[% FOREACH item IN report.rows.values %] <tr> <td>[% item.id %]</td> <td>[% item.delta %] %</td> </tr> [% END %]
Please note that the only difference between the above 2 code is "category1" vs "values"
The Template module version I'm using is 2.24. Not sure if it is because this is an older version that does not support keys & values keyword within % ... %
Anyone has any idea how I can fix it?
Thank you so much!!!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Template + html: hash keys and values keyword not working
by hippo (Archbishop) on May 07, 2016 at 21:59 UTC | |
by feiiiiiiiiiii (Acolyte) on May 08, 2016 at 02:22 UTC | |
by Bod (Parson) on Mar 12, 2024 at 23:34 UTC | |
by afoken (Chancellor) on Mar 13, 2024 at 19:34 UTC |