in reply to Nested LOOP in HTML::Template

You probably want this line:
push @outer, { 'INNER' => @inner };
to be this:
push @outer, { 'INNER' => \@inner };
otherwise you are setting the value of the INNER key to a scalar - the size of the @inner array.

You'll also want to declare the @inner inside the while() loop, otherwise you'll find that each INNER's value holds the same data.

Replies are listed 'Best First'.
Re^2: Nested LOOP in HTML::Template
by nedals (Deacon) on May 10, 2005 at 22:34 UTC

    I tried that but the @inner array gets cleared within the if statement and the reference now points to an empty array. However, having messed with this most of the afternoon, I came up with this that seems to work.

    Making $inner a ref to an array and de-referencing for the push seems to solve the problem.

    my @outer = (); my $inner = []; my $n = 0; while (<DATA>) { chomp; push @$inner, { DATA => $_ }; if ($n == 1) { push @outer, { INNER => $inner }; $inner = []; $n = 0; } else { $n++; } }