in reply to Sort lists/Data Structures
First, to make posted code legible, you need to use <code> tags.
You could try writing your own test for the sort method, which would solve your issue. A second approach, assuming your names are unique, would be to create a new hash with names as keys and references to records as values. You could then sort your keys and cycle through that array on the hash, i.e.
my %hash_by_name; for (@records) { $hash_by_name{$_->{name}} = $_; } my @sorted_names = sort keys %hash_by_name; while (@sorted_names) { push @sorted, $hash_by_name{shift @sorted_names}; }
Note the above will fail if you have repeat names.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort lists/Data Structures
by mmontemuro (Initiate) on Dec 05, 2008 at 20:38 UTC |