# assumption: @words == @numbers
use Data::Dumper;
my @words = qw(I Am Cool);
my @numbers = qw(1 2 3);
my @loop_data = map {
{
WORD => $words[$_],
NUMBER => $numbers[$_],
}
} 0..$#words;
print Dumper \@loop_data;
####
sub db2tmpl {
my ($sth,@bind) = @_;
$sth->execute(@bind);
my $fields = $sth->{NAME};
my $rows = $sth->fetchall_arrayref;
my @loh;
for my $row (@$rows) {
my %hash;
@hash{@$fields} = @$row;
push @loh, {%hash};
}
return \@loh;
}
####
my $sth = $dbh->prepare('select * from student');
my $students = db2tmpl($sth);