Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Nested LOOP in HTML::Template

by moot (Chaplain)
on May 10, 2005 at 22:25 UTC ( [id://455784]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://455784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-24 02:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found