Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How to sort a multidimensional array

by HuckinFappy (Pilgrim)
on Jul 11, 2006 at 04:19 UTC ( [id://560304]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    Jeff Goldblum Actor
    Mary Heartman Priest
    ...
    
    
    How can I sort on Vocation?
    
  2. or download this
    my @data = ( [ qw(Jeff Goldblum Actor) ],
                 [ qw(Mary Heartman Priest) ],
                 [ qw(John Ericsson Mathmetician) ],
                 [ qw(Tony Cisneros Chef) ], );
    
  3. or download this
    my @sorted = map  { $_->[0] }              # Line 4
                 sort { $a->[1] cmp $b->[1] }  # Line 3
                 map  { [ $_, $_->[2] ] }      # Line 2
                 @data;                        # Line 1
    
  4. or download this
    my @data = ( [ qw(Jeff Goldblum Actor) ],
                 [ qw(Mary Heartman Priest) ],
    ...
    for ( @sorted ) {
       printf "%s %s - %s\n", @{ $_ };
    }
    
  5. or download this
    fappy@flux[16] perl /tmp/sortit
    Jeff Goldblum - Actor
    Tony Cisneros - Chef
    John Ericsson - Mathmetician
    Mary Heartman - Priest
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-24 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found