packetstormer has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I am really struggling to extract the correct information in perl templates. A Dumper file is below and I simply want to extract the value of the e2eventname key but I can't. The whole array of hashes thing is melting my brain!
I have tried the loop below (and many other variations) but no joy.

[% FOREACH element IN e2event %] [% element.e2eventname %] [% END %]
Would anyone know?
$VAR1 = { 'e2event' => [ { 'e2eventprovidername' => 'XYT', 'e2eventdescription' => 'All the latest football news.', 'e2eventstart' => '1315919400', 'e2eventservicename' => '103 - XYT', 'e2eventcurrenttime' => '1315922112.7', 'e2eventremaining' => '588', 'e2eventname' => 'The Football Show', 'e2eventtitle' => 'The Football Show', 'e2eventduration' => '3300', 'e2eventid' => '1237', 'e2eventservicereference' => '1:0:1:2585:7FB:2:11A0000:0:0:0::103 - XY +T' }, { 'e2eventprovidername' => 'XYT', 'e2eventdescription' => 'All the new shows. 'e2eventstart' => '1315922700', 'e2eventservicename' => '103 - XYT', 'e2eventcurrenttime' => '1315922112.99', 'e2eventremaining' => '1800', 'e2eventname' => 'News', 'e2eventtitle' => 'News', 'e2eventduration' => '1800', 'e2eventid' => '1657', 'e2eventservicereference' => '1:0:1:2585:7FB:2:11A0000:0:0:0::103 - XY +T' } ] };

Replies are listed 'Best First'.
Re: Templates and hash arrays?
by keszler (Priest) on Sep 13, 2011 at 14:17 UTC

    Think normal 'for' loop:

    for my $element (@e2event) { print $element->{e2eventname}; }

    Note: NOT $e2event->{e2eventname}

      Hi, I actually had a type in my first post the I have fixed, I should have read exactly as you say - but that doesn't work!

        OK - I assumed that the e2event in your foreach was the e2event value from the $VAR1 dumped.

        [% FOREACH element IN VAR1.e2event %] [% element.e2eventname %] [% END %]

        Replace VAR1 with the actual variable you dumped.

        To see how the template sees your variable:

        [% USE Dumper indent=2 %] [% Dumper.dump(some_variable) %]