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:$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, }, };
Which yields me:[% FOREACH ip = data %] this is ip [% ip %] counter is [% ip.counter %] [% END %]
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:this is ip is HASH(0x9c68328) counter is this is ip is HASH(0x9c62e68) counter is this is ip is HASH(0x9c62d0c) counter is
and then:in the same object: 'ips' => [ '10.1.7.142', '10.1.7.11', '10.1.7.112' ],
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![% FOREACH ip in ips %] this is ip is [% ip %] counter is [% ip.counter %] [% END %]
In reply to Template Toolkit and unpredictable hashrefs by rastoboy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |