Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Welcome to the Monastery
 
PerlMonks  

(tye)Re: Sorting multi dimensional arrays

by tye (Sage)
on Mar 14, 2001 at 23:12 UTC ( [id://64569]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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")

Replies are listed 'Best First'.
Re: (tye)Re: Sorting multi dimensional arrays
by Anonymous Monk on Oct 07, 2002 at 10: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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://64569]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.