in reply to Re^6: Find Prefix if regex didn't match
in thread Find Prefix if regex didn't match
Show code and prove it, its easy
#!/usr/bin/perl -- use Benchmark qw/ cmpthese /; print "$]\n"; cmpthese( -3, { circumcised => sub { my $what = 'WWWA'; $what =~ /AB.*Z/gc; # fail one $what .='DBBBABC'; pos($what) = 8; $what =~ /AB.*Z/gc; # fail another return; }, uncut => sub { my $what = 'WWWA'; $what =~ /AB.*Z/gc; # fail one $what .='DBBBABC'; $what =~ /AB.*Z/gc; # fail another return; }, }, ); print "\n\n"; cmpthese( -3, { circumcised => sub { my $what = 'WWWA'; $what =~ /AB.*Z/gc; # fail one $what .='DBBBABCZ'; pos($what) = 8; $what =~ /AB.*Z/gc; # match one return; }, uncut => sub { my $what = 'WWWA'; $what =~ /AB.*Z/gc; # fail one $what .='DBBBABCZ'; $what =~ /AB.*Z/gc; # match one return; }, }, ); print "\n\n"; cmpthese( -3, { circumcised => sub { my $what = 'WWWA'; $what =~ /AB.*Z/gc; # fail one $what .='DBBBABCZ'; substr $what, 0, 8, ''; $what =~ /AB.*Z/gc; # match one return; }, uncut => sub { my $what = 'WWWA'; $what =~ /AB.*Z/gc; # fail one $what .='DBBBABCZ'; $what =~ /AB.*Z/gc; # match one return; }, }, ); print "\n\n"; cmpthese( -3, { circumcised => sub { my $what = 'WWWA'; $what =~ /AB.*Z/; # fail one $what .='DBBBABCZ'; substr $what, 0, 8, ''; $what =~ /AB.*Z/; # match one return; }, uncut => sub { my $what = 'WWWA'; $what =~ /AB.*Z/; # fail one $what .='DBBBABCZ'; $what =~ /AB.*Z/; # match one return; }, }, ); print "\n\n"; __END__
5.014001 Rate circumcised uncut circumcised 370001/s -- -70% uncut 1245010/s 236% -- Rate circumcised uncut circumcised 301014/s -- -41% uncut 506153/s 68% -- Rate circumcised uncut circumcised 398024/s -- -19% uncut 492750/s 24% -- Rate circumcised uncut circumcised 554597/s -- -26% uncut 749156/s 35% --
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^8: Find Prefix if regex didn't match
by demoralizer (Beadle) on Nov 06, 2012 at 12:16 UTC | |
by Anonymous Monk on Nov 06, 2012 at 13:18 UTC | |
by demoralizer (Beadle) on Nov 07, 2012 at 06:31 UTC |
In Section
Seekers of Perl Wisdom