The /p modifier introduced in 5.10 makes ${^PREMATCH}, {$^MATCH}, and ${^POSTMATCH} available for use after matching. It is assumed it is faster than using $`, $& and $'. But when I benchmark this code:
I've got:pl@nereida:~/src/perl/perltesting$ cat ./timeregexpwithp.pl #!/usr/local/lib/perl/5.10.1/bin//perl5.10.1 -w use strict; use Benchmark qw{:all}; cmpthese( 1000000, { p => q{'hola juan' =~ /ju/p; my ($a, $b, $c) = (${^PREMATCH}, ${^M +ATCH}, ${^POSTMATCH} ) }, oldway => q{'hola juan' =~ /ju/; my ($a, $b, $c) = ($`, $&, $') } } ); cmpthese( 10000000, { pnoassign => q{'hola juan' =~ /ju/p; }, oldwaynoassign => q{'hola juan' =~ /ju/; } } );
It seems that the old way is faster. Any explanations?pl@nereida:~/src/perl/perltesting$ ./timeregexpwithp.pl Rate p oldway p 892857/s -- -6% oldway 952381/s 7% -- Rate oldwaynoassign pnoassign oldwaynoassign 3184713/s -- -1% pnoassign 3225806/s 1% --
Thanks
In reply to The /p modifier in Perl5.10 regexps by casiano
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |