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

Schwartzian Transform vs. Building Hash of Function Results, Then Sorting on Function Results

by davebaker (Monk)
on Oct 16, 2006 at 18:54 UTC ( #578571=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        my @output =
          map { $_->[0] }
          sort { $a->[1] cmp $b->[1] }
          map { [$_, expensive_func($_)] }
        @input;
    
  2. or download this
        foreach $_ (@input) {
            $result_for{$_} = expensive_func($_);
        }
    ...
        my @output
            = sort { $result_for{$a} cmp $result_for{$b}
                   } @input;
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-07-29 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls