On Tue Dec 07 18:24:22 2010, RJRAY wrote:
Show quoted text> This is a feature request.
>
> RegularExpressions::ProhibitFixedStringMatches already looks for
> constant-string expressions. Could it be considered to have it look for
> constant-substring expressions, as well?
>
> Given:
>
> $a =~ /foo/
>
> it should suggest using "index" instead of a regular expression.
> Obviously this would not apply to s///, only to m// and qr//.
Some thoughts:
1) My opinion (clearly labeled as such) is that fixed substring matches
would be a separate policy.
2) I did some fiddling around once with index($a, 'foo') versus $a =~
/foo/, and found that though index($a, 'foo') was faster than $a =~
/foo/, it was not that much faster, and by the time you tested the
result of the index() to see if you had a match, it was actually slower.
The proper testing of the index() result is another puzzle to me, since
I think the right way is to compare to $[, but that is being deprecated.
3) I think the index() construction violates the principal of least
surprise, since it makes Perl look like Fortran. This is admittedly a
minor point, but I was unable to restrain myself.
None of the above should be considered authoritative; they are just my
thoughts on the subject. Yes, I am disinclined to implement, but if
someone else wants to I will not oppose. I will take the liberty of
marking this ticket 'wishlist', though.
This is another case where I wish for a thriving ecosystem of one-policy
distributions, so people who like this can install and use it, and
people who do not can ignore it.