Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > unexplained warning message in m{...} regexp

Reply
Thread Tools

unexplained warning message in m{...} regexp

 
 
Klaus
Guest
Posts: n/a
 
      04-24-2009
I am trying to match a literal string '{0,0}' using the syntax m{...}.
I know that I have to escape both the '{' and '}' characters.

Here is my program
========================
use strict;
use warnings;

$_ = '{0,0}';
if (m{\A\{0,0\}\z}) {
print "yes\n";
}
else {
print "no\n";
}
========================

The regexp works as intended and prints "yes", but there is an
unexplained warning message:

========================
Quantifier unexpected on zero-length expression in regex; marked by
<-- HERE in m/\A{0,0}\z <-- HERE / at Testregexp.pl line 5.
yes
========================

The message does not appear if I use /\A\{0,0\}\z/.

It seems to me that Perl is confused about using '{' and '}' inside a
match of the form m{...}

I am using Activestate Perl 5.10 on Windows XP.

C:\>perl -v

This is perl, v5.10.0 built for MSWin32-x86-multi-thread
(with 5 registered patches, see perl -V for more detail)

Copyright 1987-2007, Larry Wall

Binary build 1004 [287188] provided by ActiveState http://www.ActiveState.com
Built Sep 3 2008 13:16:37

--
Klaus
 
Reply With Quote
 
 
 
 
Frank Seitz
Guest
Posts: n/a
 
      04-24-2009
Klaus wrote:
>
> It seems to me that Perl is confused about using '{' and '}' inside a
> match of the form m{...}


Perl is not confused. It's a syntax error, because { and } have a special
meaning in regexes. See perldoc perlre (Section "Quantifiers").

Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
 
Reply With Quote
 
 
 
 
Klaus
Guest
Posts: n/a
 
      04-24-2009
On Apr 24, 10:32*am, Frank Seitz <(E-Mail Removed)> wrote:
> Klaus wrote:
>
> > It seems to me that Perl is confused about using '{' and '}' inside a
> > match of the form m{...}

>
> Perl is not confused. It's a syntax error, because { and } have a special
> meaning in regexes. See perldoc perlre (Section "Quantifiers").


Please note that I have escaped '\{' and '\}' inside m{\A\{0,0\}\z}...

....and why does the message disappear if I use /\A\{0,0\}\z/. ?

--
Klaus
 
Reply With Quote
 
Frank Seitz
Guest
Posts: n/a
 
      04-24-2009
Klaus wrote:
> On Apr 24, 10:32 am, Frank Seitz <(E-Mail Removed)> wrote:
>> Klaus wrote:
>>>
>>> It seems to me that Perl is confused about using '{' and '}' inside a
>>> match of the form m{...}

>> Perl is not confused. It's a syntax error, because { and } have a special
>> meaning in regexes. See perldoc perlre (Section "Quantifiers").

>
> Please note that I have escaped '\{' and '\}' inside m{\A\{0,0\}\z}...


Here, the \-escape eliminates the meaning as delimiter.
The { } become metacharacters.

> ...and why does the message disappear if I use /\A\{0,0\}\z/. ?


Here, the \-escape eliminates the meaning as metacharacter.
The { } become normal characters.

Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
 
Reply With Quote
 
Teo
Guest
Posts: n/a
 
      04-24-2009
Dear Franz,

On Apr 24, 10:32*am, Frank Seitz <(E-Mail Removed)> wrote:
> Klaus wrote:
>
> > It seems to me that Perl is confused about using '{' and '}' inside a
> > match of the form m{...}

>
> Perl is not confused. It's a syntax error, because { and } have a special
> meaning in regexes. See perldoc perlre (Section "Quantifiers").


No is not: the curly brackets are correctly escaped. The problem only
occurs if {} are used: other bracketing delimiters (e.g., m(\A\{0,0\}
\z) ) do not provoke the warning.

I can reproduce the problem with both 5.8.9 and 5.10.0

Matteo
 
Reply With Quote
 
Frank Seitz
Guest
Posts: n/a
 
      04-24-2009
Teo wrote:
> On Apr 24, 10:32 am, Frank Seitz <(E-Mail Removed)> wrote:
>> Klaus wrote:
>>
>>> It seems to me that Perl is confused about using '{' and '}' inside a
>>> match of the form m{...}

>> Perl is not confused. It's a syntax error, because { and } have a special
>> meaning in regexes. See perldoc perlre (Section "Quantifiers").

>
> No is not: the curly brackets are correctly escaped. The problem only
> occurs if {} are used: other bracketing delimiters (e.g., m(\A\{0,0\}
> \z) ) do not provoke the warning.
>
> I can reproduce the problem with both 5.8.9 and 5.10.0


See <(E-Mail Removed)>

Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
 
Reply With Quote
 
Helmut Wollmersdorfer
Guest
Posts: n/a
 
      04-24-2009
Klaus wrote:
> I am trying to match a literal string '{0,0}' using the syntax m{...}.
> I know that I have to escape both the '{' and '}' characters.
>
> Here is my program
> ========================
> use strict;
> use warnings;
>
> $_ = '{0,0}';
> if (m{\A\{0,0\}\z}) {
> print "yes\n";
> }

[...]
> ========================
> Quantifier unexpected on zero-length expression in regex; marked by
> <-- HERE in m/\A{0,0}\z <-- HERE / at Testregexp.pl line 5.
> yes
> ========================


Same here - Perl 5.19 on Debian/Linux.

Seems to be bug.

Workarounds:

m{\A[{]0,0[}]\z}
m{\A\{0\,0\}\z}

Helmut Wollmersdorfer
 
Reply With Quote
 
Teo
Guest
Posts: n/a
 
      04-24-2009
On Apr 24, 10:58*am, Frank Seitz <(E-Mail Removed)> wrote:
> Klaus wrote:
> > On Apr 24, 10:32 am, Frank Seitz <(E-Mail Removed)> wrote:
> >> Klaus wrote:

>
> >>> It seems to me that Perl is confused about using '{' and '}' inside a
> >>> match of the form m{...}
> >> Perl is not confused. It's a syntax error, because { and } have a special
> >> meaning in regexes. See perldoc perlre (Section "Quantifiers").

>
> > Please note that I have escaped '\{' and '\}' inside m{\A\{0,0\}\z}...

>
> Here, the \-escape eliminates the meaning as delimiter.
> The { } become metacharacters.
>
> > ...and why does the message disappear if I use /\A\{0,0\}\z/. ?

>
> Here, the \-escape eliminates the meaning as metacharacter.
> The { } become normal characters.


Ok I see but this is rather confusing:

* in a // delimited regex the literal '/' has to be escaped
* in a {} delimited regex the literal '{' has *not* to be escaped

am I getting it right?

But then when I look at perlop

When searching for single-character delimiters, escaped delimiters
and "\\" are skipped. For example, while
searching for terminating "/", combinations of "\\" and "\/" are
skipped. If the delimiters are bracketing, nested
pairs are also skipped. For example, while searching for closing
"]" paired with the opening "[", combinations of
"\\", "\]", and "\[" are all skipped, and nested "[" and "]" are
skipped as well. However, when backslashes are
used as the delimiters (like "qq\\" and "tr\\\"), nothing is
skipped. During the search for the end, backslashes
that escape delimiters are removed (exactly speaking, they are not
copied to the safe location).

it gets more confusing. If I understand correctly the difference is
only there if the { } are paired.
In m{ aaa{bbb } the { is not escaped and it is understood as the
beginning of a quantifier.

In fact I get:

Search pattern not terminated at ./test.pl line 6.

So to have a literal '{' I should escape it if not paired and not
escape it if not paired.

Did I get it wrong? (I sincerly hope so

Matteo
 
Reply With Quote
 
Klaus
Guest
Posts: n/a
 
      04-24-2009
On Apr 24, 10:58*am, Frank Seitz <(E-Mail Removed)> wrote:
> Klaus wrote:
> > On Apr 24, 10:32 am, Frank Seitz <(E-Mail Removed)> wrote:
> >> Klaus wrote:

>
> >>> It seems to me that Perl is confused about using '{' and '}' inside a
> >>> match of the form m{...}
> >> Perl is not confused. It's a syntax error, because { and } have a special
> >> meaning in regexes. See perldoc perlre (Section "Quantifiers").

>
> > Please note that I have escaped '\{' and '\}' inside m{\A\{0,0\}\z}...

>
> Here, the \-escape eliminates the meaning as delimiter.


I see, thanks for the explanation.

> The { } become metacharacters.


I find it unfortunate that they become metacharacters, particularly so
because there is no reason to quote metacharacters { } in the first
place, as they always come in pairs and are handled natuarally by m{...
{ }...} as a nested pair of curlies, for example m{a{1,2}}

--
Klaus
 
Reply With Quote
 
Klaus
Guest
Posts: n/a
 
      04-24-2009
On Apr 24, 11:12*am, Helmut Wollmersdorfer <(E-Mail Removed)>
wrote:
> Klaus wrote:
> > I am trying to match a literal string '{0,0}' using the syntax m{...}.
> > I know that I have to escape both the '{' and '}' characters.

>
> > Here is my program
> > ========================
> > use strict;
> > use warnings;

>
> > $_ = '{0,0}';
> > if (m{\A\{0,0\}\z}) {
> > * * print "yes\n";
> > }

> [...]
> > ========================
> > Quantifier unexpected on zero-length expression in regex; marked by
> > <-- HERE in m/\A{0,0}\z <-- HERE / at Testregexp.pl line 5.
> > yes
> > ========================

>
> Same here - Perl 5.19 on Debian/Linux.
>
> Seems to be bug.
>
> Workarounds:
>
> m{\A[{]0,0[}]\z}
> m{\A\{0\,0\}\z}


Thanks for the workarounds, they work ok. But I agree that the
original problem is a bug. Where can I post a bug report ?

--
Klaus
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
warning C4244 (VC7.0) unexplained!!! Geoff Noel C++ 3 02-02-2005 02:42 AM
NEWBIE:unexplained syntax error Michiel Perl 2 09-10-2004 02:54 PM
unexplained bad performance of multipoint gre tunnel ... Garry Glendown Cisco 1 12-26-2003 10:23 AM
Unexplained Instance Error Marty Cruise ASP .Net 4 07-03-2003 09:27 PM



Advertisments