in reply to Re^2: Sorting an array of hashes with an exeption
in thread Sorting an array of hashes with an exception

BrowserUK you're the boss! It works great, thank you so much!
  • Comment on Re^3: Sorting an array of hashes with an exeption

Replies are listed 'Best First'.
Re^4: Sorting an array of hashes with an exeption
by BrowserUk (Patriarch) on May 08, 2013 at 20:08 UTC

    In response to your /msg (it's easier to reply here than in a bunch of /msgs):

    I was wondering a little about your method you provided on my question regarding sort. It works just as I want but Im just curious about how its working. Im pretty new to Perl and I've not seen that kind of syntax berfore regarding ? and :

    Essentially, the conditional (or ternary) operator:boolean expr ? expr1 : expr2 is similar to if( boolean expr ) { expr1 } else { expr2 }, except that the former is an expression rather than a statement, and thus has a residual value once evaluated.

    In the case of the sort block:

    $a->{routedistance} && $b->{routedistance} ? $a->{routedistance} <=> $b->{routedistance} : $a->{distance} <=> $b->{distance}

    it says: if both routedistances are true (are non-zero), then return the result of comparing them; else return the result of comparing the two distances.

    See Conditional operator for (a little) more.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I see, thanks for clearing that up for me, I really appreciate it.