That code was suppose to sort by valuesYou're nearly there...
$a and $b are special variables and are not the same as $i and $j in your example... see sortmy %hash; for my $i (0 .. $#fname) { $hash{ "$fname[$i] $lname[$i]" } = $state[$i] } # sort the keys by value for my $key ( sort { $hash{$a} cmp $hash{$b} } keys %hash ) { print "$key $hash{$key}\n"; } # alternatively my @sorted = sort { $hash{$a} cmp $hash{$b} } keys %hash; for my $key ( @sorted ) { print "$key $hash{$key}\n"; }
In reply to Re^5: Creating a hash from arrays
by tangent
in thread Creating a hash from arrays
by cspctec
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |