Sorting arrays of intervals in perl?
perl
Solution
You need to extract first number for every element, and do numerical comparison using `<=>` operator,
my @array = qw(1-5 7-9 10-15 20-58 123-192 234-256);
my @sorted = sort {
my ($aa,$bb) = map /^([0-9]+)/, $a,$b;
$aa <=> $bb;
} @array;
Problem
I have an array in perl with some intervals like: @array = qw(1-5 7-9 10-15 20-58 123-192 234-256) I am trying to order it using sort but this is what I obtain: 1-5 , 10-15 , 123-192 , 20-58 , 234-256 , 7-9 It is sorted by the first character of the first number... How can be ordered by the whole first number in order to obtain the next array? 1-5 , 7-9 , 10-15 , 20-58 , 123-192 , 234-256 Thank you very much! P.S. I have no code for this, I am trying the command ``` my @sorted = sort @array; ```