Re: records returned by DBI::selectall_hashref() are not ordered



Yu Wang [YW], on Friday, May 27, 2005 at 05:50 (+0000 (UTC)) wrote
these comments:

$ref_rsch = $dbh->>selectall_hashref('
YW> Any ideas and suggestions?

yes, as you maybe know, hashes in Perl aren't ordered for some
purposes (security & speed). If you have to use hashref, just order
them in program, as you order normal hashes. I use for example:

$hr->{categories} = get_categories($hr);
^^-- make hash in hashref (subquery)

$hr->{categories_index} = [ sort { $a <=> $b } keys %{$hr->{categories}} ]
^^-- get ordered list by categories (HoH)


$hr->{cattable_index} = [ reverse sort { $hr->{$a}{counter} <=>
$hr->{$b}{counter} } keys %{$hr} ];
^^- sort that by value

--

How do you protect mail on web? I use http://www.2pu.net

[He's a modest little person, with much to be modest about]


.



Relevant Pages