you build an array, break it down to sort, then add to it again. how about using element 3 from the array in the hash already for the compare...# Place all the hash data into an array of pipe-seperated values for s +orting foreach my $key (keys %test) { push @sorted, "$key|$test{$key}->[0]|$test{$key}->[1]|" . "$test{$key}->[2]|$test{$key}->[3]"; } # Sort the data by the number in the last part of the array. @sorted = map $_->[1], sort { $a->[0] <=> $b->[0] } map [ substr($_,rindex($_,'|')+1), $_ ], @sorted; # Put the line breaks back in. for (@sorted) { $_ = "$_\n"; }
# Sort the data by the number in the last part of the array @sorted = # return just the hash->key map { $_->[1] } # compare hash->key->value[3]'s sort { $a->[0] <=> $b->[0] } # anon array w/ hash->key->value[3], hash->key map { [ %test->{$_}->[3], $_ ] } # keys from hash keys %test; # rebuild array of pipe-seperated values, and put the line breaks back + in $_.="|$test{$_}[0]|$test{$_}[1]|$test{$_}[2]|$test{$_}[3]\n" for(@sort +ed);
~Particle
In reply to Re: Learning to use the hash effectively
by particle
in thread Learning to use the hash effectively
by Stamp_Guy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |