Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How does DBI return an arrayref with key/value pairs?

by hdb (Prior)
on Jun 21, 2013 at 14:34 UTC ( #1040184=note: print w/ replies, xml ) Need Help??


in reply to How does DBI return an arrayref with key/value pairs?

From http://search.cpan.org/~timb/DBI-1.53/DBI.pm:

You may often want to fetch an array of rows where each row is stored as a hash. That can be done simple using:

my $emps = $dbh->selectall_arrayref( "SELECT ename FROM emp ORDER BY ename", { Slice => {} } ); foreach my $emp ( @$emps ) { print "Employee: $emp->{ename}\n"; }

So despite the name you get a reference to an array of hash references.

UPDATE: Have you tried looking at it using Data::Dumper? Should show the structure being a hash at the bottom.


Comment on Re: How does DBI return an arrayref with key/value pairs?
Download Code
Re^2: How does DBI return an arrayref with key/value pairs?
by walkingthecow (Friar) on Jun 21, 2013 at 14:48 UTC
    Well, my tired eyes must need some sleep, because I seem to have glazed right over that when reading that. I was getting bothered at the fact that at one point it says, " It returns a reference to an array containing a reference to an array (or hash, see below)" and was thinking, "See below where?!" Turns out I either need glasses or some sleep. Thanks for clearing that up for me.

    I did do a print Dumper on it, and what I was seeing was a hash, but somewhere I read in the documentation (trying to find it now) that it returns "a reference to an array of array refs," and my brain was thinking, "Wow, so somehow a reference to an array of array refs becomes a hash?" Silly brain.

      That is a very useful observation, hdb.   Meanwhile, walkingthecow, I hope that you did not take my rather-flippant comment wrongly.   Nothing was intended, but upon re-read I see that it could have slapped.   Hope not.   (But if not ... “it was moooo...”)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040184]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (14)
As of 2014-10-21 17:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (106 votes), past polls