I am not sure what you mean by sort it. It is not possible to sort a hash in same sense as sorting an array. You can process the contents of the hash in any order. Refer: perldoc -q "sort a hash".
Also be warned that sorting names can be quite tricky. The following example should get you started. Note use of "Schwartzian Transformation" also described in perfaq4 under: perdoc -q "sort an array"
Update: Removed incorrect check of first names.use strict; use warnings; use Data::Dumper; my %books=( '34' => ['enlgish', 'dani M. rod', 54], '24' => ['spanish', 'ramk rovale', 41], '54' => ['enlgish', 'bob falicas', 17], ); my @sorted_list = map {$books{$_->[0]}} sort {lc $a->[1] cmp lc $b->[1]} map {[$_,$books{$_}[1] =~ /\b(\w+)$/]} keys %books ; print Dumper \@sorted_list;
In reply to Re: sorting hash by a certain value (that it is in an array)
by BillKSmith
in thread sorting hash by a certain value (that it is in an array)
by gooyava
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |