Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

(tye)Re: Sorting multi dimensional arrays

by tye (Cardinal)
on Mar 15, 2001 at 04:12 UTC ( #64569=note: print w/ replies, xml ) Need Help??


in reply to Sorting multi dimensional arrays

my $sample= [ [5,7,2], [9,4,8], [1,6,3] ]; my @widths= map 0+@$_, @$sample; my @sort= sort map @$_, @$sample; $sample= [ map { [ splice @sort, 0, $_ ] } @widths ];

But if you really wanted to not pull it apart to sort it:

use mapcar; my $sample= [ [5,7,2], [9,4,8], [1,6,3] ]; my @refs= sort {$$a cmp $$b} map \(@$_), @$sample; mapcar { my( $ref, $val )= @_; $$ref= $val; } \@refs, [ map $$_, @refs ];

Which requires that you grab my mapcar.

        - tye (but my friends call me "Tye")


Comment on (tye)Re: Sorting multi dimensional arrays
Select or Download Code
Re: (tye)Re: Sorting multi dimensional arrays
by Anonymous Monk on Oct 07, 2002 at 14:14 UTC
    sorting a list of names into alphabetical orders using arrays
      change cmp to <=>

      rdfield

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2014-07-12 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls