Re: sorting an array of hashrefs
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Tue, 29 Aug 2006 19:48:06 GMT
monkeys paw wrote:
The following is intended to sort an array of hash refs based on
id_type. It is not working however. Does anyone know why?
use Data::Dumper;
our %datatype_sort = (
bill => 0,
reg => 10,
);
my @ary = (
{id_type => 'reg', id => 'KY200616813'},
{id_type => 'bill', id => 'CA2005000A5'},
{id_type => 'bill', id => 'CA2005000A250'},
);
my @x = sort _sortval_datatype @ary;
print Dumper(\@x);
sub _sortval_datatype {
my($av, $bv) = @_;
return $datatype_sort{$av->{id_type}} <=>
$datatype_sort{$bv->{id_type}};
}
sub _sortval_datatype {
return $datatype_sort{$a->{id_type}} <=> $datatype_sort{$b->{id_type}};
}
John
--
use Perl;
program
fulfillment
.
- References:
- sorting an array of hashrefs
- From: monkeys paw
- sorting an array of hashrefs
- Prev by Date: FAQ 6.22 How can I match strings with multibyte characters?
- Next by Date: Windows Service - Determine if someone is logged in at the console
- Previous by thread: sorting an array of hashrefs
- Next by thread: Re: sorting an array of hashrefs
- Index(es):
Relevant Pages
|
|