in reply to Re: Sorting an array of hashes with an exeption
in thread Sorting an array of hashes with an exception
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Sorting an array of hashes with an exeption
by choroba (Cardinal) on May 09, 2013 at 07:39 UTC | |
|
Re^3: Sorting an array of hashes with an exeption
by martin_87 (Initiate) on May 08, 2013 at 17:30 UTC | |
by BrowserUk (Patriarch) on May 08, 2013 at 20:08 UTC | |
by martin_87 (Initiate) on May 08, 2013 at 20:25 UTC |