bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
While I have read other posts on PerlMonks, and knocked around the Interwebs a bit, I'm not finding exactly what I'm looking or.
I want to keep the keys/values in the same order for every array element in an AoH ref.
my $stmt = "SELECT firstname, lastname, city, state FROM addresses ORD +ER BY lastname"; my $data = $self->dbh->selectall_arrayref($stmt, {Slice => {}});
Data::Dumper returns:
[ { 'lastname' => 'Smith', 'city' => 'Chicago', 'state' => 'IL', 'firstname' => 'Jim' }, { 'city' => 'Cleveland', 'state' => 'OH', 'firstname' => 'Susan', 'lastname' => 'Jones' }, { 'state' => 'FL', 'lastname' => 'Waters', 'firstname' => 'Sam', 'city' => 'Miami' } ];
I'd like to have:
[ { 'firstname' => 'Jim', 'lastname' => 'Smith', 'city' => 'Chicago', 'state' => 'IL' }, { 'firstname' => 'Susan', 'lastname' => 'Jones', 'city' => 'Cleveland', 'state' => 'OH' }, { 'firstname' => 'Sam', 'lastname' => 'Waters', 'city' => 'Miami', 'state' => 'FL' } ];
I was thinking this might work, but result is the same.
use Tie::IxHash; my $data = {}; tie %$data, 'Tie::IxHash'; my $stmt = "SELECT firstname, lastname, city, state FROM addresses ORD +ER BY lastname"; $data = $self->dbh->selectall_arrayref($stmt, {Slice => {}});
What am i not understanding? Thanks!
—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Using Tie::IxHash to keep database query keys/values in order
by huck (Prior) on Feb 15, 2017 at 22:52 UTC | |
by huck (Prior) on Feb 15, 2017 at 23:00 UTC | |
by bradcathey (Prior) on Feb 15, 2017 at 23:09 UTC | |
by AnomalousMonk (Archbishop) on Feb 16, 2017 at 00:52 UTC | |
Re: Using Tie::IxHash to keep database query keys/values in order
by Anonymous Monk on Feb 15, 2017 at 23:17 UTC | |
by bradcathey (Prior) on Feb 16, 2017 at 13:30 UTC | |
by haukex (Archbishop) on Feb 16, 2017 at 13:50 UTC |
Back to
Seekers of Perl Wisdom