in reply to Sort hash keys
If, on the other hand, both numerical parts of your key are variant then you can split on the hyphen and do numerical sorts on each.
knoppix@Microknoppix:~$ perl -E ' > my %seq = map { $_ => 1 } qw{ > 1035-2341 > 1047-835 > 1035-2347 > 874-3971 > 1035-65 > 874-70 > 1035-46 > }; > say for > map { $_->[ 0 ] } > sort { $a->[ 1 ] <=> $b->[ 1 ] || $a->[ 2 ] <=> $b->[ 2 ] } > map { [ $_, ( split m{-} ) ] } > keys %seq;' 874-70 874-3971 1035-46 1035-65 1035-2341 1035-2347 1047-835 knoppix@Microknoppix:~$
I hope this is helpful.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort hash keys
by kalyanrajsista (Scribe) on Sep 17, 2010 at 11:00 UTC |