in reply to regex: extract a substring
#!/usr/bin/perl -wd use strict; use Benchmark; timethese( 50000, { 'regex' => sub { ®ex(); }, 'ind_sub' => sub { &ind_sub(); }, } ); sub regex { $_ = "abchelloxyz"; m/abc(.*?)xyz/; my $bar = $1; } sub ind_sub { $_ = "abchelloxyz"; my $x = index( $_, "abc") + 3; my $y = index( $_, "xyz"); my $bar = substr( $_, $x, $y - $x); }
-derby
|
|---|