cyrus_dlx has asked for the wisdom of the Perl Monks concerning the following question:
and for easy printing of what we got:my @people= (); my @names = qw(jack peter smith jason patrick sylvia randa debbie dian +e john gina solomon fances jojo kwame nana esi francis ato justice); for my $i (0 .. $#names) { my %hash = (); $hash{"age"} = int(rand 75) + 1; $hash{"name"} = $names[$i]; push (@people, \%hash); }
# some sort algorithm goes here @sorted = sort by_name @people; for $i (0 .. $#sorted) { my %person = %{$sorted[$i]}; print "$person{name} is $person{age} years old.\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting an array of hashes by hash field
by holli (Abbot) on Apr 01, 2005 at 00:37 UTC | |
|
Re: Sorting an array of hashes by hash field
by tlm (Prior) on Apr 01, 2005 at 00:43 UTC | |
by cyrus_dlx (Initiate) on Apr 01, 2005 at 00:56 UTC | |
|
Re: Sorting an array of hashes by hash field
by Roy Johnson (Monsignor) on Apr 01, 2005 at 01:44 UTC |