Hi Monks! I'm having a devil of a time comprehending what Template::Toolkit wants from me. I have an object that resembles this:
$VAR1 = { '10.1.7.142' => { 'counter' => 2, 'clusterstatus' => on, }, '10.1.7.11' => { 'counter' => 3, 'clusterstatus' => off, }, '10.1.7.112' => { 'counter' => 3, 'clusterstatus' => on, }, };
As you can see, I'm collecting information about different IP's. I don't know in advance what they will be. I send the object itself to the template code, which looks like this:
[% FOREACH ip = data %] this is ip [% ip %] counter is [% ip.counter %] [% END %]
Which yields me:
this is ip is HASH(0x9c68328) counter is this is ip is HASH(0x9c62e68) counter is this is ip is HASH(0x9c62d0c) counter is
So I expect to get "HASH(0x...)" for the $ip variable, but I don't understand why I can't access ip.counter. I've even tried making a separate hashref with a simple list of ip's in the hash and iterating through that:
in the same object: 'ips' => [ '10.1.7.142', '10.1.7.11', '10.1.7.112' ],
and then:
[% FOREACH ip in ips %] this is ip is [% ip %] counter is [% ip.counter %] [% END %]
But with that I get nothing at all, like it can't find the 'ips' key. In the past when I'm using key names that are predictable, I haven't had any trouble, but this one is kicking my behind. It appears I'm misapprehending something basic--any input would be greatly appreciated!

In reply to Template Toolkit and unpredictable hashrefs by rastoboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.