in reply to Re: Nested LOOP in HTML::Template
in thread Nested LOOP in HTML::Template

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++; } }