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
Warning if regexp used as LHS of =~ instead of RHS #15622
Comments
From @epaCreated by @epaThis program contains a mistake: % perl -wE '$re = qr/a/; $s = "abc"; if ($re =~ $s) { say "hi" }' The match operator is the wrong way round; it should be $s =~ $re. If warnings are enabled, and the LHS of the =~ operator is a regular use warnings; $s =~ $re; # OK The second and third cases above *could* warn, but for the purpose of Perl Info
|
From @AbigailOn Thu, Sep 22, 2016 at 08:38:55AM -0700, Ed Avis wrote:
Who says it's a mistake? I've certainly written code which introspects And I don't always write /$pattern/ on the RHS of a =~ operator. Abigail |
The RT System itself - Status changed from 'new' to 'open' |
From @ap* Abigail <abigail@abigail.be> [2016-09-22 22:00]:
I’ve done that, but extremely rarely. I wonder if warning the user when
strict.pm and warnings.pm themselves do that. :^) Courtesy of yours Not gonna fly. Regards, |
From @ap* Aristotle Pagaltzis <pagaltzis@gmx.de> [2016-09-26 06:48]:
No. Any time a value crosses an authority boundary, like when a value is Not gonna fly. Not as part of perl proper. However: package Regexp { use overload q[""] => sub { die } } Looks like that does what you’d think it’ll do. And returning $_[0] So anyone who wants as much can already have it. Regards, |
From @epaAristotle Pagaltzis wrote:
This is true. But the proposal was to warn only if the LHS of =~ is a regexp and the RHS is not. sub match_and_report { Now, if this code is called the wrong way round, transposing the string and regexp arguments, isn't it reasonable for it to warn? This is surely analogous to the warnings on uninitialized values. Every time a value crosses into a module's code, it 'would have to defensively check against undef'. I suggest that using =~ 'the wrong way round' is if anything more likely to be a mistake than doing something like undef()+5, and is at least as worthy of a runtime warning, bearing in mind that warnings can be turned on and off. -- This email is intended only for the person to whom it is addressed and may contain confidential information. Any retransmission, copying, disclosure or other use of, this information by persons other than the intended recipient is prohibited. If you received this email in error, please contact the sender and delete the material. This email is for information only and is not intended as an offer or solicitation for the purchase or sale of any financial instrument. Wadhwani Asset Management LLP is a Limited Liability Partnership registered in England (OC303168) with registered office at 9th Floor Orion House, 5 Upper St Martin’s Lane, London, WC2H 9EA. It is authorised and regulated by the Financial Conduct Authority. |
Migrated from rt.perl.org#129333 (status was 'open')
Searchable as RT129333$
The text was updated successfully, but these errors were encountered: