in reply to How do you specify which fields to sort by when sorting an array.

There are several examples given in the documentation for sort. The trick is specifying which fields of $a and $b to compare:
my @output; while (<INPUT_FILE>) { push @output, [ split(',', $_, 4) ]; } my @sorted = sort { $a->[0] cmp $b->[0] || $a->[3] <=> $b->[3] } @output;
I took the liberty of fixing the name of @outputRef (which is not a reference) and pushing each row as an anonymous array. I also use numeric comparisons on the phone numbers.
  • Comment on Re: How do you specify which fields to sort by when sorting an array.
  • Download Code