Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

RFC: yet another sorting technique

by blazar (Canon)
on Jul 27, 2005 at 15:37 UTC ( [id://478647]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @sorted=do{
        my $n;
        my %stuff=map { func($_) . ':' . $n++ => $_ } @unsrt;
        @stuff{sort keys %stuff};
    };
    
  2. or download this
    my @sorted=do{
        my @keys=map func($unsrt[$_]) . ":$_", 0 .. $#unsrt;
        @unsrt[ map +(split /:/)[-1], sort @keys ];
    };
    
  3. or download this
    my @sorted=@unsrt[ map +(split /:/)[-1],
        sort map func($unsrt[$_]) . ":$_", 0 .. $#unsrt ];
    
  4. or download this
    my @sorted=map $unsrt[ (split /:/)[-1] ],
      sort map func($unsrt[$_]) . ":$_", 0 .. $#unsrt;
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-06-21 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.