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

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

Thread Previous
From:
Abigail
Date:
June 3, 2008 09:34
Subject:
Re: [perl #54702] Feature: regexp modifier to disable interpolation like m''
Message ID:
20080603163354.GC3946@abigail.be
On Mon, Jun 02, 2008 at 12:37:40PM -0700, Bram via RT wrote:
> On Fri May 23 03:01:21 2008, eda@waniasset.com wrote:
> >
> > Normally in m// and s/// the pattern is double-quote interpolated.
> > You can avoid this by choosing '' as the delimiter.  But that's not
> > always very readable (PBP for example recommends using only // and {}
> > as delimiters).  And of course the pattern might contain ' 
> characters.
> > 
> > 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;
> > 
> > where the /n modifier turns off interpolation.
>  
> I don't really like the idea of adding a modifier to supress 
> interpolation...
> 
> Currently there is:
>   $string =~ m/Pattern with a literal \$ sign/;  and
>   $string =~ m'Pattern with a literal \$ sign';

Given that $ has a meaning in regexes, and that "$ sign" doesn't
interpolate in qr// or m// context (it does interpolate in qq// context,
go figure), this is a very poor example. $ would need escaping anyway.

Perhaps /foo@example\.com/ is a better example.

> Personally, I have never ever used m'' and I don't see a reason to use /
> n over \. 
> 
> 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?

Well, in that case, you already have to look at the end to know whether
it's using /x or not. If you're there, you might as well look for other
modifiers.

> Also according to:
> http://www.regular-expressions.info/refflavors.html  JGSoft and .NET 
> are already using the  n  modifier for an explicit capture which can 
> make it very confusing (for people coming from JGSoft and/or .NET) and/
> or for regex tools.

I'd be surprised if there wasn't some other letter that could be used.

But don't take this post of me as an argument in favour of the proposed
suggestion; it isn't. But the proposal doesn't hinge on the exact name
of the modifier; the fact some other languages uses it for its own purpose
sounds like a very weak argument against the proposal.

I like the idea of being able to do a non-interpolating pattern - just
as we have C<qq> and C<q> for strings, but then as a different operator.
But that should have been long time ago, not worth breaking code now. 


Abigail

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