Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

RE: Schwartzian Transform

by perlmonkey (Hermit)
on Apr 27, 2000 at 12:36 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://9380]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 00:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found