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

The Ovidian Transform

by Ovid (Cardinal)
on Dec 31, 2001 at 13:21 UTC ( #135353=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    @new_list =
        map  { $_->[0] }
        sort { $a->[1] <=> $b->[1] }
        map  { [ $_, expensive_function( $_ ) ] }
        @old_list;
    
  2. or download this
    a_bunch_of_random_letters|19670620|and_some_more_random_letters
    
  3. or download this
    sub get_date_perl
    {
        my $date = substr( $_[0], index( $_[0], '|' ) + 1, 8 );
        return join '', unpack( "A4A2A2",$date );
    }
    
  4. or download this
    SV* get_date( char* str )
    {
        /* some stuff goes here */
        return newSVpv(date,8);
    }
    
  5. or download this
    #!/usr/bin/perl -w
    use strict;
    ...
        return newSVpv( date, 8 );
    }
    END_OF_C_CODE
    
  6. or download this
    my $date = get_date( $string );
    
  7. or download this
    sub get_date_perl
    {
    ...
        my ( $month, $day, $year ) = unpack( "A2A2A4",$date );
        return $year.$month.$day;
    }
    
  8. or download this
    SV* get_date (char* str)
    {
    ...
        new_date[7] = date[3];
        return newSVpv(new_date,8);
    }
    
  9. or download this
    Benchmark: timing 50 iterations of Inline, Perl...
        Inline: 41 wallclock secs (40.72 usr +  0.00 sys = 40.72 CPU) @  1
    +.23/s (n=50)
          Perl: 53 wallclock secs (53.21 usr +  0.00 sys = 53.21 CPU) @  0
    +.94/s (n=50)
    
  10. or download this
    @new_list =
        map_sort { $a->[1] <=> $b->[1] }
        map      { [ $_, expensive_function( $_ ) ] }
        @old_list;
    
  11. or download this
    Benchmark: timing 50 iterations of Inline, Ovidian, Perl...
        Inline: 41 wallclock secs (40.72 usr +  0.00 sys = 40.72 CPU) @  1
    +.23/s (n=50)
       Ovidian: 34 wallclock secs (34.71 usr +  0.00 sys = 34.71 CPU) @  1
    +.44/s (n=50)
          Perl: 53 wallclock secs (53.21 usr +  0.00 sys = 53.21 CPU) @  0
    +.94/s (n=50)
    
  12. or download this
    #!/usr/bin/perl -w
    use strict;
    ...
        new_date[7] = date[3];
        return newSVpv(new_date,8);
    }
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-09-19 04:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls