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

Re: [perl #101938] Oddity of /p

Thread Previous | Thread Next
From:
Abigail
Date:
October 22, 2011 07:46
Subject:
Re: [perl #101938] Oddity of /p
Message ID:
20111022144553.GA32457@almanda
On Fri, Oct 21, 2011 at 09:08:11PM -0700, Eric Brine wrote:
> # New Ticket Created by  "Eric Brine" 
> # Please include the string:  [perl #101938]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=101938 >
> 
> 
> This is a bug report for perl from ikegami@adaelis.com,
> generated with the help of perlbug 1.39 running under perl 5.14.0.
> -----------------------------------------------------------------
> 
> Hi,
> 
> Does the "p" modifier apply to the operator (like "o") or the pattern (like
> "s")? It seems to me it applies to the operator.
> 
> That said, (?:) supports p, although it has no effect (sometimes with
> warning, sometimes without).
> 
> >perl -wE"'x' =~ /x/p or die; say ${^MATCH} // '-';"
> x
> 
> >perl -wE"'x' =~ /(?p:x)/ or die; say ${^MATCH} // '-';"
> -
> 
> >perl -wE"'x' =~ /(?-p:x)/p or die; say ${^MATCH} // '-';"
> Useless use of (?-p) in regex; marked by <-- HERE in m/(?-p <-- HERE :x)/ at
> -e line 1.
> x
> 
> Except sometimes it does have an effect.
> 
> >perl -wE"$re=qr/x/p; 'x' =~ /${re}/ or die; say ${^MATCH} // '-';"
> x
> 
> >perl -wE"$re=qr/x/p; 'xy' =~ /${re}y/ or die; say ${^MATCH} // '-';"
> -

That can be explained by the fact that /${re}/ doesn't do a
stringification-regexp compile roundtrip, where /${re}y/ does.
It's a side-effect of the optimization.

> 
> And then there's the case where (?-p:) warns even though it appears to work.
> 
> >perl -wE"$re=qr/x/p; 'x' =~ /$re/ or die; say ${^MATCH} // '-';"
> x
> 
> >perl -wE"$re=qr/x/p; 'x' =~ /(?-p:$re)/ or die; say ${^MATCH} // '-';"
> Useless use of (?-p) in regex; marked by <-- HERE in m/(?-p <-- HERE
> :(?^up:x))/ at -e line 1.
> -

Again, that's due to the stringification-regexp compile roundtrip. 
Replacing (?-p by (?-i makes it print '-' as well.

> 
> >From a user's perspective, none of this makes no sense. It was probably done
> this way so C<< $re = qr/.../p; $_ =~ $re >> works, but that doesn't really
> make sense either. "p" should be a m// modifier, it shouldn't be qr//
> modifier, and it should be allowed in (?:).


Abigail

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