//'s not necessary if $regex was built with qr.
Actually, if you leave out the slashes, the regex is put in string context, and the speed gain is lost.
I've even seen people do bizarre things because they think qr//s are faster without slashes:$foo =~ '^string literal$'; # Does not equal /\Q^string literal$/ $foo =~ $string; $foo =~ subroutine(); $foo =~ bareword; # Unless $INC{'strict.pm'} $foo =~ $precompiled_regex; # Is stringified first! $foo =~ /$precompiled_regex/; # Faster
# Bad: (well, it works, but not the way you want it to) $foo =~ $qr; $foo =~ s//bar/; # Good: $foo =~ s/$qr/bar/;
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
In reply to Re: Re: Set::Scalar - Regexp as method parameter?
by Juerd
in thread Set::Scalar - Regexp as method parameter?
by PetaMem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |