Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Custom Sort An AoA

by kcott (Archbishop)
on Apr 02, 2014 at 04:01 UTC ( [id://1080675]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    @list = sort { @$a <=> @$b || do {
        my $cmp;
        ($cmp = $a->[-$_] cmp $b->[-$_]) ? last : next for 1 .. @$a;
        $cmp;
    } } @list;
    
  2. or download this
    #!/usr/bin/env perl
    
    ...
    
    use Data::Dump;
    dd \@list;
    
  3. or download this
    [
      ["one"],
    ...
      ["zzz", "def", "ghi"],
      ["blah", "asdf", "foo", "bar"],
    ]
    
  4. or download this
    #!/usr/bin/env perl
    
    ...
    
    sub cmp_alpha { $_[0] cmp $_[1] }
    sub cmp_num { $_[0] <=> $_[1] }
    
  5. or download this
    [
      ["one"],
    ...
    ]
    [[1], [2], [7, 8, 1], [5, 3, 6], [9, 3, 6], [0 .. 3]]
    [[2], [1], [9, 3, 6], [5, 3, 6], [7, 8, 1], [0 .. 3]]
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-03-28 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found