Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   regex bug (comments within regex not as robust) (http://www.velocityreviews.com/forums/t894888-regex-bug-comments-within-regex-not-as-robust.html)

kg.google@olympiakos.com 10-27-2005 07:01 PM

regex bug (comments within regex not as robust)
 
Code:

if
(
$x =~
/
\d+ # this slash / generates an error
/x
)
{
}

version:
activestate perl 5.8.7

regards,
Kiriakos Georgiou


Dave 10-27-2005 07:06 PM

Re: regex bug (comments within regex not as robust)
 

<kg.google@olympiakos.com> wrote in message
news:1130438696.203137.108570@z14g2000cwz.googlegr oups.com...
> Code:
>
> if
> (
> $x =~
> /
> \d+ # this slash / generates an error
> /x
> )
> {
> }
>
> version:
> activestate perl 5.8.7
>
> regards,
> Kiriakos Georgiou
>


This is not a bug. The compiler doesn't see the /x switch until it has found
the limits of the regex, so the / in the comment gives it a false ending
(see the footnote on p148 of the camel book). If you want to use / in your
comments use {} (or something else)as regex delimiters.



Dave 10-27-2005 07:09 PM

Re: regex bug (comments within regex not as robust)
 

"Dave" <daveandniki@ntlworld.com> wrote in message
news:43612527$0$1012$8fcfb975@news.wanadoo.fr...
>
> <kg.google@olympiakos.com> wrote in message
> news:1130438696.203137.108570@z14g2000cwz.googlegr oups.com...
>> Code:
>>
>> if
>> (
>> $x =~
>> /
>> \d+ # this slash / generates an error
>> /x
>> )
>> {
>> }
>>
>> version:
>> activestate perl 5.8.7
>>
>> regards,
>> Kiriakos Georgiou
>>

>
> This is not a bug. The compiler doesn't see the /x switch until it has
> found the limits of the regex, so the / in the comment gives it a false
> ending (see the footnote on p148 of the camel book). If you want to use /
> in your comments use {} (or something else)as regex delimiters.
>
>


and also the perlre manpage where the /x switch is explained says:

Note that you have to be careful not to include the pattern delimiter in
the comment--perl has no way of knowing you did not intend to close the
pattern early



Paul Lalli 10-27-2005 07:21 PM

Re: regex bug (comments within regex not as robust)
 
kg.google@olympiakos.com wrote:
> Code:
>
> if
> (
> $x =~
> /
> \d+ # this slash / generates an error
> /x
> )
> {
> }
>
> version:
> activestate perl 5.8.7


I don't know how you can call it a bug when this limitation of the /x
feature are perfectly well documented in
`perldoc perlre`

Paul Lalli



All times are GMT. The time now is 12:13 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.