The code:
the output:
1
5
400
500
My question is why is that weird code producing that weird output? This is not real code, I am just asking out of curiousity sake since I was not able to explain it myself.
sort_by_num appears to be doing nothing but it does have an affect on the sort function since the output should be:
1
400
5
500
using just a straight sort:
@arr = sort (@arr);
Code:
sub sort_by_num {
return $a <=> $b;
}
@arr = (500,1,400,5);
foreach (sort sort_by_num(@arr)) {
print ("$_\n");
}
the output:
1
5
400
500
My question is why is that weird code producing that weird output? This is not real code, I am just asking out of curiousity sake since I was not able to explain it myself.
sort_by_num appears to be doing nothing but it does have an affect on the sort function since the output should be:
1
400
5
500
using just a straight sort:
@arr = sort (@arr);