in reply to Re: Double sort in hash values
in thread Double sort in hash values

Let's explain what's going on here.

The <=> operator returns -1, 0, or 1 depending on the comparison results. If the terms being compared are equal, zero is returned. Zero also happens to be what Perl thinks of as false. This is important.

The logical short circuit 'or' operator '||' evaluates the left hand side for truth. If the lefthand side evaluates to false, 'or' then looks to the righthand side. This is also important.

Putting it all together... If the lefthand comparison contains unequal terms, the comparison operator returns -1 or 1, both of which are 'true', and the righthand comparison never gets evaluated. If the lefthand comparison contains equal terms, the <=> opearator returns 0 (false), so the || (or) operator then evaluates the expression on the righthand side.

You can chain together multiple expressions this way. The expressions with higher priority should be on the left, and the lower priority should be on the right. The ones further to the right will only be evaluated if the ones further to the left all evaluate to 'equal'.


Dave