Help for this page

Select Code to Download


  1. or download this
    use strict;
    use Benchmark qw/timethese/;
    ...
            $nth .= $_ if $h{space} == $index-1 && /\S/ .. !/\S/
        }
    }
    
  2. or download this
    Benchmark: timing 100000 iterations of FindNth_Grantm, FindNth_Jasper,
    FindNth_Pg, FindNth_Roger, FindNth_Ysth, FindNth_Zaxo_Array,
    ...
    @ 5396.36/s
    FindNth_Zaxo_Split: 14 wallclock secs (14.51 usr +  0.02 sys = 14.53 C
    +PU)
    @ 6882.31/s
    
  3. or download this
    # Pg's approach
    my ($nth) = ($str =~ m/(\w+\s*){$index}/);
    ...
    # Grantm's approach
    my $idx = $index - 1;
    my ($nth) = $str =~ /(?:\w+\W+){$idx}(\w+)/;