Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 63718
Status: open
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: rjray [...] blackperl.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: RegularExpressions::ProhibitFixedStringMatches could report on /foo/ as well
Download (untitled) / with headers
text/plain 565b
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//. -- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Randy J. Ray Silicon Valley Scale Modelers: http://www.svsm.org rjray@blackperl.com randy.j.ray@gmail.com
Download (untitled) / with headers
text/plain 1.5k
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.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.