- or download this
'vanilla' => sub {
if ($text =~ /gotcha/) {
$pre = $`;
...
}
},
}
- or download this
print "vanilla\n";
print "prematch :", $`, "\n";
print "match :", $&, "\n";
print "postmatch :", $', "\n";
- or download this
Benchmark: timing 500000 iterations of substr, unpack, vanilla...
substr: 5 wallclock secs <snip> @ 106678.05/s
unpack: 8 wallclock secs <snip> @ 54241.70/s
vanilla: 0 wallclock secs <snip> @ 492125.98/s
- or download this
my ($i, $j, $k);
for ('a' .. 'z', 'A' .. 'Z') {
$i++ if $text2 =~ /$_/;
}
$j++ if $text3 =~ /quux/;
$k++ if $text4 =~ /H/;
- or download this
substr: 25 wallclock secs ...
unpack: 26 wallclock secs ...
vanilla: 26 wallclock secs ...
- or download this
use strict;
use warnings;
use Benchmark qw(timethese);
...
sub substr_postmatch {
substr( $_[0], $+[0] )
}