develooper Front page | perl.perl5.porters | Postings from August 2012

Re: [perl #54702] Feature: regexp modifier to disable interpolationlike m''

Thread Previous | Thread Next
From:
demerphq
Date:
August 21, 2012 00:31
Subject:
Re: [perl #54702] Feature: regexp modifier to disable interpolationlike m''
Message ID:
CANgJU+VLdXFYWZ-mJRqR40Rh390V39b98jS3MUEXd9-X5AfGyA@mail.gmail.com
On 21 August 2012 09:18, Father Chrysostomos via RT
<perlbug-followup@perl.org> wrote:
> On Tue Jun 03 09:10:09 2008, eda@waniasset.com wrote:
>> >>As an alternative to m'', how about a pattern modifier /n to
>> >>suppress interpolation?
>> >>
>> >>Old style: $string =~ m'Pattern with a literal $ sign';
>> >>
>> >>Proposed new style: $string =~ /Pattern with a literal $ sign/n;
>>
>> >Personally, I have never ever used m'' and I don't see a
>> >reason to use / n over \.
>>
>> m'' is used rarely but when you need it, it's most handy.  The classic
>> example is matching an RCS version string like $Id: xxx$ or $Revision:
>> xxx$.  I recognize that some people will prefer to use backslashes.
>>
>> >A reason against it:
>> >You need to look at the end of the regex to know wheter or not
>> >things get interolated. What if the regex is using the /x
>> >modifiers and takes 10 lines?
>>
>> I think /x is exactly the precedent in favour.  You have to look to
>> the end of the regex to see if it has /x making comments and
>> whitespace insignificant.  This doesn't seem to be a problem in
>> practice.
>>
>> >Also according to:
>> >http://www.regular-expressions.info/refflavors.html  JGSoft
>> >and .NET are already using the  n  modifier for an explicit
>> >capture
>>
>> The exact letter isn't important, it could be /d or whatever.
>
> ’Fraid this can’t work.
>
> A here-doc is supposed to start on the line following the marker.
>
> So what do we do in this case?
>
> sub n { 34 }
> s( ${ <<END } )
> - Just another Perl hacker
> END
> *-*n;
>
> If we don’t interpolate, we have
>
> [ ${ <<END } ]
>
> as our pattern and
>
> [ Just another Perl hacker
> END
> *]
>
> as our replacement.  That is followed by *n which is intepreted as
> multiplication followed by a sub call.  The lack of an /n flag means we
> should have interpolated.
>
> If we do interpolate, then we have
>
> [ ${ <<END } ]
>
> as our pattern,
>
> [- Just another Perl hacker
> ]
>
> as the body of the here-doc, and
>
> [-]
>
> as our replacement.  Then we have an /n flag after that that tells us we
> should not have interpolated.


Sounds more like an argument to get rid of here docs in silly places
than it is an argument about this subject.

Yves


-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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