New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regexp syntax check when variables contained with \Q...\E #15644
Comments
From @epaCreated by @epaWhen possible regular expressions are compiled and checked at program compile time. sub f { /(/ } But when the regexp includes variables, this early checking cannot be done. $x = 'a'; In general, this has to be so. Perl can't know what the possible However, when building a regexp you may choose to use the \Q...\E If the variable appears in the regexp protected by \Q...\E then the sub f { /(\Q$x\E/ } No matter the value of $x at run time, this will never be a valid One possible way to do this would be to try making a munged version of There might be a better way to do this checking depending on * Further discussion Not strictly part of the bug report, but I would like to mention a The other major way to build up a regexp from variables is to include my $re = qr/whatever/; This is always going to be an invalid regexp as long as $re holds a Suppose there were a way for the programmer to specify his or her my $re_1 = qr/hel+o/; At the point when $re is compiled, and the values of $re_1 and $re_2 In itself, this might catch a few bugs but is perhaps not worth the my $re = qr/whatever/; Here Perl can know that since $re is always going to be a compiled Finally, only for those who enjoy the bondage and discipline, an Perl Info
|
From @AbigailOn Tue, Oct 04, 2016 at 07:29:05AM -0700, Ed Avis wrote:
I don't see much of a benefit of this. You'd be adding an additional Abigail |
The RT System itself - Status changed from 'new' to 'open' |
From @epaYes, the advantage is that of compile-time checking of regular expressions. Speaking personally, I find this one of the advantages of Perl over other scripting languages, where a regexp syntax error is caught only at run time. There is a small overhead associated with compiling the regular expression even though it may not in the end be used. |
Migrated from rt.perl.org#129803 (status was 'open')
Searchable as RT129803$
The text was updated successfully, but these errors were encountered: