Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Passing array of references to Template

by philipbailey (Deacon)
on Aug 23, 2011 at 19:54 UTC ( #921984=note: print w/replies, xml ) Need Help??

in reply to Passing array of references to Template

You simply need a second loop, something like this (untested):

[% FOR line IN results %] [% FOR item IN line %] [% item %] [% END %] [% END %]

And in answer to should I deference it, bind the columns and then sent it to Template?--no, it's not necessary, and in fact Template Toolkit does not do what one expects (or at least what I expect) if you use arrays directly, as opposed to an array ref, for arrays with one element. It's safest to always use array refs.

Replies are listed 'Best First'.
Re^2: Passing array of references to Template
by packetstormer (Monk) on Aug 23, 2011 at 20:01 UTC
    Is it FOR or FOREACH? I had been trying (and having some success with FOREACH) Regardless, neither of them work!

      FOR and FOREACH are completely interchangeable. I prefer the former, but either is fine.

      I would suggest that you convince us (or yourself, at least) that $results contains what you expect, e.g. using Data::Dumper.

      Update: it occurs to me that @sendoff is never defined. Did you really run this using strict? You don't seem to need $sendoff or @sendoff at all: just write

      $template->param('results' => $results);
        Yeah - printing the \@sendoff via Dumper displays what I need. I actually have a typo in what I posted, the actual code is
        my $results = &return_values; my @sendoff = @$results;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2022-01-18 17:48 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (53 votes). Check out past polls.