develooper Front page | perl.perl5.porters | Postings from July 2008

[PATCH] Unintented interpolation of $/ in regex (was: Re: [perl#35877] \n after $ in regex (was: Strange regex failure?))

Thread Previous | Thread Next
From:
Bram
Date:
July 24, 2008 09:16
Subject:
[PATCH] Unintented interpolation of $/ in regex (was: Re: [perl#35877] \n after $ in regex (was: Strange regex failure?))
Message ID:
20080724181427.aiml4sdvr40k4coc@horde.wizbit.be
Citeren Yitzchak Scott-Thoennes <sthoenna@efn.org>:

> On Mon, June 2, 2008 1:52 pm, Bram wrote:
>> Quoting David Nicol <davidnicol@gmail.com>:
>>> Warn that non-final $ will interpolate in documentation and suggest
>>> \Z instead?
>>
>> Given how easy it is to miss it I feel more for a
>> 'Possible unintended interpolation of $\ in regex' warning. (if that
>> is even possible of course)
>>
>> Any comments on the warning?
>
> Sounds great, if you can make it suppressable with ${\}.
>

Patch attached.

./perl -wle '"" =~ m/$\s/;'
Possible unintended interpolation of $\ in regex at -e line 1.

./perl -Ilib -Mdiagnostics -wle '"" =~ m/$\s/;'
Possible unintended interpolation of $\ in regex at -e line 1 (#1)
     (W ambiguous) You said something like m/$\/ in a regex.
     The regex m/foo$\s+bar/m translates to: match the word 'foo', the output
     record separartor (see perlvar/$\) and the letter 's' (one time or more)
     followed by the word 'bar'.

     If this is what you intended then you can silence the warning by using
     m/${\}/ (for example: m/foo${\}s+bar/).

     If instead you intended to match the word 'foo' at the end of the line
     followed by whitespace and the word 'bar' on the next line then  
you can use
     m/$(?)\/ (for example: m/foo$(?)\s+bar/).

./perl -wle '"" =~ m/${\}s/;'

./perl -Ilib -Mdiagnostics -wle '"" =~ m/${\}s/;'


Not sure tho if the text in perldiag is clear enough...

Kind regards,

Bram


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About