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.
In reply to AoH refs for setting HTML::Template loops by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |