in reply to Sorting array
# changed your array to an array of arrays: my @arr = ( [ 'ch1', 100 ], [ 'ch2', 20 ], [ 'ch1', 13 ], [ 'ch2', 45 +], [ 'ch1', 1 ] ); # sort by chromosome then by position: my @sorted = sort { $a->[0] cmp $b->[0] or $a->[1] <=> $b->[1] } @arr; use Data::Printer; p @sorted; __END__ [ [0] [ [0] "ch1", [1] 1 ], [1] [ [0] "ch1", [1] 13 ], [2] [ [0] "ch1", [1] 100 ], [3] [ [0] "ch2", [1] 20 ], [4] [ [0] "ch2", [1] 45 ] ]
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Sorting array
by NetWallah (Canon) on Jun 14, 2013 at 23:38 UTC | |
by frozenwithjoy (Priest) on Jun 15, 2013 at 00:34 UTC | |
by rkk (Novice) on Jun 15, 2013 at 02:48 UTC | |
by NetWallah (Canon) on Jun 15, 2013 at 02:57 UTC | |
by rkk (Novice) on Jun 15, 2013 at 02:55 UTC | |
by rkk (Novice) on Jun 14, 2013 at 23:57 UTC |
In Section
Seekers of Perl Wisdom