develooper Front page | perl.perl5.porters | Postings from June 2016

Re: RFC: deprecate quantifying zero-length constructs in regexpatterns

Thread Previous | Thread Next
From:
Abigail
Date:
June 2, 2016 09:42
Subject:
Re: RFC: deprecate quantifying zero-length constructs in regexpatterns
Message ID:
20160602094408.GA8504@almanda.fritz.box
On Wed, Jun 01, 2016 at 10:56:42PM -0600, Karl Williamson wrote:
> This came up on another thread, but I think it should get its own airing.
>
> qr/ ^ {1,3} /x, warns with "Quantifier unexpected on zero-length expression"
>
> qr/ ^ * /x warns instead with "^ *  matches null string many times", and  
> generates code that will run a very long time.
>
> qr/ ^ ? /x doesn't warn.  Nor does qr/ ^ {0,1} /x.  But qr/ ^ {0,2} /x  
> does warn.
>
> It is nonsensical to use a quantifier on an assertion, and for Perl to  
> try to do so is not likely at all to be DWIM.  So I believe we should  
> deprecate these.


I'd say it's about as nonsensical as multiplying 0 with something,
or doing C< "" x 5 >, but we aren't deprecating those either.

I grant you, there are many examples where it doesn't make sense, 
but it makes generating patterns easier if "$SUB_PATTERN$QUANTIFIER"
is always valid, regardless whether $SUB_PATTERN is a zero-length
expression.

Just as generated code doesn't have to care whether something on 
the LHS of a multiplication is 0.


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