CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How to loop through hash ref of hash refs?

 



bulrush
User

Oct 21, 2014, 4:30 AM

Post #1 of 2 (2691 views)
How to loop through hash ref of hash refs? Can't Post

- Perl 5.18.2 on Ubuntu 14.04
- DBI version: 1.63
- SQLite version: 3.8.4.1


I'm using SQLite and the method fetchrow_array() never returns records, so I want to use another method, fetchall_hashref(), which returns a hash ref of hash refs.

My question is: how do I loop through all these keys to get the db key fields and associated data? I'm a bit rusty on hashrefs and perreftut didn't help.

Thanks.
-----


BillKSmith
Veteran

Oct 21, 2014, 5:31 AM

Post #2 of 2 (2689 views)
Re: [bulrush] How to loop through hash ref of hash refs? [In reply to] Can't Post

If the order of the keys does not matter:

Code
my $response = fetchrow_array(....); 
while (my( $key, $row) = each %$response) {
print $key, $row->{column_name};
}

Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives