Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How do you specify which fields to sort by when sorting an array.

by chromatic (Archbishop)
on Jul 14, 2002 at 22:51 UTC ( [id://181660]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://181660]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found