Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > hashed array in array need the keys... and length

Reply
Thread Tools

hashed array in array need the keys... and length

 
 
Daniel
Guest
Posts: n/a
 
      08-14-2003
By using this code I made an array from a hashed array
to regain a table content and layout as received from a mysql database...

my $sth = $dbh->prepare("SELECT * FROM `Groepen';");
$sth->execute();
while (my $Content = $sth->fetchrow_hashref){
$array[$counter++]=$Content;
}

This part works just fine.. how ever
I need to view the keys (column names) seperatly so
I can put the table together on a webpage...
also length of the hashed array would be nice
so I could make it more dynamic...

Any suggestions please ?S?

Thanks

Daniel


 
Reply With Quote
 
 
 
 
Kevin Collins
Guest
Posts: n/a
 
      08-14-2003
"Daniel" <(E-Mail Removed)> wrote in message news:<3f3b9d3c$0$49100$(E-Mail Removed)4all.nl>...
> By using this code I made an array from a hashed array
> to regain a table content and layout as received from a mysql database...
>
> my $sth = $dbh->prepare("SELECT * FROM `Groepen';");
> $sth->execute();
> while (my $Content = $sth->fetchrow_hashref){
> $array[$counter++]=$Content;
> }
>
> This part works just fine.. how ever
> I need to view the keys (column names) seperatly so
> I can put the table together on a webpage...
> also length of the hashed array would be nice
> so I could make it more dynamic...
>


Actually, what you created is an array of hash references... You can
get the column names a couple of ways:

# non-ordered list of field names as an array
# this will need to be in your loop
@cols = keys(%{$Content});

OR

# ordered list of field names as an array ref.
$cols_ref = $sth->{NAME}

You'll have to post more info on what you want to do with the column
names for anything more than that.

Not sure what you are asking for by "length"... what you are storing
is a reference to a hash.

Kevin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SqlMembershipProvider and Hashed Passwords Glenn ASP .Net 0 06-28-2007 03:29 PM
how do you do a hashed array of a class? santogold@mn.rr.com Ruby 2 05-12-2006 07:26 AM
Advice on converting hashed packages to pseudo-hashed packages Ian Perl Misc 3 02-12-2005 12:17 AM
Importing 80+ hashed and 1 array into several perl scripts Matt Breedlove Perl 1 11-24-2003 09:47 PM
Is Cookies hashed by default Tommy ASP .Net 0 08-06-2003 06:26 PM



Advertisments