Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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?
[marto]: Even with shell command recall I find it less time consuming to do such things in a file.
[marto]: I very seldom use one liners for anything which isn't utterly trivial
[Discipulus]: i'm wise enough to never use my oneliners
[Discipulus]: anyway marto, i read th CB logs.. osteopat is what you need

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2017-09-22 08:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (260 votes). Check out past polls.

    Notices?