Fellow monasterians,

I'm still trying to get my head around references and was doing okay until this bit of code where I must set an HTML::Template loop with a AoH. I'm fine when I fetchall_arrayref() and set the param with the AoH reference directly:

my $branches = $sth->fetchall_arrayref(); ... $template->param( branches => $branches );

But when I try to build a new AoH for the purposes of the application's functionality and set that ref, I get an error of trying to set the "param with a scalar." I tried this:

my $branchaoh = \$selbranch;

and

my $branchaoh = \@selbranch;

after the for loops and my @selbranch; before the loops and got strict errors for both. So, question: how do I make my $selbranch an acceptable reference for H::T? Background questions: when does $selbranch become an array? a reference? Here's the whole deal:

my $stmt = "SELECT id, name FROM branches"; &execute_it; my $branches = $sth->fetchall_arrayref(); $stmt = "SELECT branches FROM users WHERE username = '$user'"; &execute_it; my @sqldata = $sth->fetchrow_array(); my @areas = split (/,/, $sqldata[0]); my $selbranch; foreach my $i (0 .. $#areas) { foreach my $j (0 .. $#$branches) { if ($areas[$i] == $branches->[$j]{'id'}) { $selbranch->[$i]{ 'value' } = $areas[$i]; $selbranch->[$i]{ 'branch' } = $branches->[$j]{'name'}; } } } my $template = HTML::Template -> new(filename => "../xm_dialogs/editme +nu.tmpl"); $template->param( branches => $selbranch ); #--------------------- sub execute_it { $sth = $dbh->prepare($stmt) or die "prepare: $stmt: $DBI::errstr"; $sth->execute() or die "execute: $stmt: $DBI::errstr"; }

Thanks all.


—Brad
"A little yeast leavens the whole dough."

In reply to AoH refs for setting HTML::Template loops by bradcathey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.