i am fetching data from a database...what i would like to achieve is for every data row fetched(id,title) to create a hash ref
{
id => data->[0],
title => data[1]
}
and push this hash ref into array ref in order to create the following format
{ category => [
{
id => 1,
title => "title1"
},
{
id => 2,
title => "title2"
}
]
}
what i have made:
my $productCategories->{category} = [];
my $product = {};
my $sth = $dbh->prepare(qq[SELECT id,title FROM ].DB_SCHEMA().qq[.product_categories]) || die $dbh->errstr;
$sth->execute() || die $dbh->errstr;
while(my $data = $sth->fetch){
$product = {
id => $data->[0],
title => $data->[1]
};
push $productCategories->{category}, $product;
}
but it is not working...