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
Back to
Seekers of Perl Wisdom