Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

RE: Schwartzian Transform

by perlmonkey (Hermit)
on Apr 27, 2000 at 12:36 UTC ( #9380=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @sorted = sort mysort @unsorted;
    sub mysort
    {
    ...
        $bb = "$2 $1";
        return $aa cmp $bb;
    }
    
  2. or download this
    @unsorted = ("Larry Wall", "Arthur C. Clarke");
    @a = map { m/(.*?)\s*(\S+)$/; [$_, "$2 $1" ] } @unsorted;
    #
    # now @a is (["Larry Wall", "Wall Larry"], 
    #            ["Arthur C. Clarke", "Clarke Arthur C."])
    #
    
  3. or download this
    my @sorted = 
               map{ $_->[0] }
               sort {$a->[1] cmp $b->[1]}
               map { m/(.*?)\s*(\S+)$/; [$_, "$2 $1" ] }
               @unsorted;
    
  4. or download this
    #!/usr/bin/perl
    use Benchmark;
    
    ...
        $bb = "$2 $1";
        return $aa cmp $bb;
    }
    
  5. or download this
    Benchmark: timing 100000 iterations of schwartzian, sort routine...
    schwartzian: 57 wallclock secs (53.66 usr +  0.30 sys = 53.96 CPU)
    sort routine: 124 wallclock secs (122.48 usr +  0.41 sys = 122.89 CPU)
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2015-07-04 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls