That's not quite right.
If one routedistance is 0 and the other not, you are comparing a routedistance with a distance, which is probably the cause of the disparity between your results and the OPs expectations.
Something like this ought to do it:
sort { $a->{routedistance} && $b->{routedistance} ? $a->{routedistance} <=> $b->{routedistance} : $a->{distance} <=> $b->{distance} } @ar;
In reply to Re^2: Sorting an array of hashes with an exeption
by BrowserUk
in thread Sorting an array of hashes with an exception
by martin_87
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |