SPUG: Loading an hashref into an array, displaying as table
Peter Darley
pdarley at kinesis-cem.com
Mon Oct 28 13:25:08 CST 2002
Ramon,
I'm not sure what you're doing with the array (I assume you're doing
something with the CGI module), but I think if you take what I did and
replace the push line with whatever you actually want, it should give you a
possible structure for doing this. What I suggest is as follows:
my @Array_Row
while (my $Row = $sth->fetchrow_hashref())
{
do some stuff
for my $Field (keys %{$Row})
{
push @Array_Row, $Field, $$Row{$Field}
# $Field = the name of the field
# $$Row{$Field} = value in the field
}
}
print table (@Array_Row);
Thanks,
Peter Darley
-----Original Message-----
From: owner-spug-list at pm.org [mailto:owner-spug-list at pm.org]On Behalf Of
Ramon Hildreth
Sent: Monday, October 28, 2002 9:54 AM
To: spug-list at pm.org
Subject: SPUG: Loading an hashref into an array, displaying as table
Hi,
I am trying to create a table in cgi, that displays the contents of an
array.
I know how to do the table part. The problem is trying to load the
array. I need to take a fetchrow_hashref, and load that into the array a
row at a time. I am thinking my basic structure will be something like
this:
While ( my $row = $sth->frechrow_hashref()0 {
Do some stuff--
foreach my $field ($row) {
push ( my @array_row, Tr
td ( $field->{contact}),
td, etc.....
}
}
Print table (@array_row);
Any help would be greatly appreciated.
Ramon Hildreth.
Ramon Hildreth
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list
mailing list