hi there,
I have a bit more complex structure (array of hash) that I am trying to loop over with FOREACH, but I am having trouble accessing the values. From the snippet below, I am trying to display:
foo --> bar
as well as
content --> perlmonks.org
but with my code I am only able to get the key, not the value, e.g:
foo ARRAY(0x8e8598c)
'main' => {
'ResultSet' => {
'foo' => 'bar',
'Listing' => [
{
'car' => '0.5',
'url' => {
'content' => 'pe
+rlmonks.org',
'type' => 'body'
},
},
{
'car' => '0.16',
'url' => {
'content' => 'so
+meotherurl.com',
'type' => 'body'
},
}
]
}
}
[% FOREACH item IN data.keys.sort %]
[% IF item == 'main' %]
[% FOREACH m IN data.main.keys.sort %]
[% IF m == 'ResultSet' %]
[% FOREACH list IN data.main.ResultSet.Listing.keys.sor
+t %]
[% IF list == 'foo' %]
<tr><td>[% list %]</td>[% data.main.ResultSet.Listi
+ng.$list %]</tr>
[% ELSIF list == 'url' %]
[% FOREACH u IN data.main.ResultSet.Listing.url %]
[% IF u == 'content' %]
<tr><td>test 3</td>[% u.content %]</tr>
[% END %]
[% END %]
[% END %]
[% END %]
[% END %]
[% END %]
[% END %]
[% END %]
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.