11

In this answer, I saw the syntax <=>; what does this mean? It seems to be some sort of comparison based on the context, but that's all I can gather. Partial context:

sub rev_by_date { $b->[9] <=> $a->[9] }
my @sorted_files = sort rev_by_date @files;
Community
  • 1
  • 1
jtpereyda
  • 6,987
  • 10
  • 51
  • 80

1 Answers1

18

From Perldoc:

Binary "<=>" returns -1, 0, or 1 depending on whether the left argument is numerically less than, equal to, or greater than the right argument. If your platform supports NaNs (not-a-numbers) as numeric values, using them with "<=>" returns undef. NaN is not "<", "==", ">", "<=" or ">=" anything (even NaN), so those 5 return false. NaN != NaN returns true, as does NaN != anything else. If your platform doesn't support NaNs then NaN is just a string with numeric value 0.

Nemo
  • 70,042
  • 10
  • 116
  • 153
bhamby
  • 15,112
  • 1
  • 45
  • 66