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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.