develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24202] Perl 5.8.0 regexp anomaly

Thread Previous
From:
Elizabeth Mattijsen
Date:
October 15, 2003 02:59
Subject:
Re: [perl #24202] Perl 5.8.0 regexp anomaly
Message ID:
p05111b02bbb2c7a54e77@[192.168.56.2]
At 21:38 -0700 10/14/03, Mario Nigrovic wrote:
>I suppose this explains why the pattern matched differently between the first
>and second applications, but I can't seem to find documentation about @+
>anywhere, including a grep for '@\\+' and even just '@' in the regexp code.

What you find to be special handling of "@" is actually standard 
quoted string interpolation.
So I doubt you will find that anywhere in the regexp code.  This has 
been a feature of Perl since at least 5.00503 (which is the oldest 
Perl I have quickly access to.  But apparently older versions did 
something wrong:

   $ perl5.00503 -e '@+ = (1,2,3); print "@+\n"'
   @+
   $ perl5.00503 -e '@a = (1,2,3); print "@a\n"'
   1 2 3

   $ perl5.6.0 -e '@+ = (1,2,3); print "@+\n"'
   @+
   $ perl5.6.0 -e '@a = (1,2,3); print "@a\n"'
   1 2 3

   $ perl5.8.0 -e '@+ = (1,2,3); print "@+\n"'
   Modification of a read-only value attempted at -e line 1.
   $ perl5.8.0 -e '@a = (1,2,3); print "@a\n"'
   1 2 3

Apparently versions before 5.8.0 allowed you to assign to @+, but 
would not interpolate @+ in the string.  So "@+" was passed to the 
regex parser.

 From version 5.8.0 onwards, @+ _is_ properly interpolated.  Causing 
it to disappear from the string is the @+ array is empty, or have 
garbage passed if the @+ array is filled with results from a previous 
regexp.

Escaping the @ with a backslash should solve your problem.  This 
should also work in the old versions code, so you shouldn't need to 
keep 2 versions of your code in that respect.



Liz

Thread Previous


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