tom123
08-01-2006, 12:13 PM
Problem trying to assign values of an array of array references (@product_records) to a hash based on colum names (@headers).
sub prepare_data_for_output() {
my $reference = shift;
my (@product_records) = @{$reference};
my $reference2 = shift;
my (@headers) = @{$reference2};
my @products_ref = ();
foreach my $row(@product_records)
{
my $h=0;
foreach my $field($product_records[$row])
{
my %products;
$products{$headers[$h]} = $field;
$h++;
}
push(@products_ref,\%products);
}
return (@products_ref);
}
(@products_ref) = &prepare_data_for_output(\@product_records, \@colums);
# Begin page output using template
print CGI::header();
# my $template = HTML::Template->new( filename => '../templates/admin_products.tmpl' );
$template->param(PRODUCTS => \@products_ref);
print $template->output();
Could someone please tell me why values are not being assigned to hash corectly.
Thanks in advance
sub prepare_data_for_output() {
my $reference = shift;
my (@product_records) = @{$reference};
my $reference2 = shift;
my (@headers) = @{$reference2};
my @products_ref = ();
foreach my $row(@product_records)
{
my $h=0;
foreach my $field($product_records[$row])
{
my %products;
$products{$headers[$h]} = $field;
$h++;
}
push(@products_ref,\%products);
}
return (@products_ref);
}
(@products_ref) = &prepare_data_for_output(\@product_records, \@colums);
# Begin page output using template
print CGI::header();
# my $template = HTML::Template->new( filename => '../templates/admin_products.tmpl' );
$template->param(PRODUCTS => \@products_ref);
print $template->output();
Could someone please tell me why values are not being assigned to hash corectly.
Thanks in advance