Help for this page

Select Code to Download


  1. or download this
    $char = chop $string while length $string > 4;
    
  2. or download this
    #!/usr/bin/perl -w
    
    ...
        "substr" => sub { ($char) = substr($string,4,1);},
        "silly"  => sub { local $string; $char = chop $string while length
    + $string > 4;},
        });
    
  3. or download this
    Benchmark: timing 150000 iterations of match, silly, substr, unpack...
         match:  4 wallclock secs ( 2.78 usr +  0.01 sys =  2.79 CPU) @ 53
    +763.44/s (n=150000)
    ...
                (warning: too few iterations for a reliable count)
        substr:  0 wallclock secs ( 0.48 usr +  0.00 sys =  0.48 CPU) @ 31
    +2500.00/s (n=150000)
        unpack:  2 wallclock secs ( 1.41 usr +  0.11 sys =  1.52 CPU) @ 98
    +684.21/s (n=150000)