Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

(tye)Re: Sorting multi dimensional arrays

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

Help for this page

Select Code to Download


  1. or download this
    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 ];
    
  2. or download this
    use mapcar;
    my $sample= [ [5,7,2], [9,4,8], [1,6,3] ];
    my @refs= sort {$$a cmp $$b} map \(@$_), @$sample;
    ...
        my( $ref, $val )= @_;
        $$ref= $val;
    } \@refs, [ map $$_, @refs ];
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-12-06 05:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (39 votes). Check out past polls.