develooper Front page | perl.perl5.porters | Postings from January 2023

Re: Making s:foo:bar: warn "reserved" - contentious idea?

Thread Previous | Thread Next
From:
Diab Jerius
Date:
January 14, 2023 20:33
Subject:
Re: Making s:foo:bar: warn "reserved" - contentious idea?
Message ID:
cffb496c-2fe7-28a3-ed8d-07a607a0dccf@avoiding.work

On 1/14/23 09:39, Paul "LeoNerd" Evans wrote:
> I have a longterm thought that one day it'd be nice if we could have
> more, and more descriptive, string quoting and regexp flags - especially
> on substitutions. For example, I'd love to be able to replace only the
> third "foo" with "bar" by doing something, maybe using syntax like this:
>
>    $str =~ s:nth(2)/foo/bar/;
>
> I haven't thought it through any further than "I would like the colon".
>
> That's a problem because currently colon just behaves like any other
> delimiting character.
>
>    $str =~ s:nth:replacement:;
>
> Oops.
>
> I would therefore like to ask how people would feel about perl printing
> a reserved-style warning whenever a quoted string or regexp uses a
> colon for its delimiter. That is to say, any of the following forms
>
>    q:string:
>    qq:interpolated string:
>    qw:quoted word list:
>    qx:executed string:
>
>    qr:regexp literal:
>    m:regexp match:
>    s:pattern:replacement:
>    tr:trans:literation: or y:trans:literation:
>
> would all print a warning something to the effect of
>
>    Use of ':' as a quotelike delimiter is reserved for possible future
>    use at FILE line LINE.
>
> For now I'm not suggesting doing anything to change the actual
> behaviour. Programs would run as they do now aside from that
> (compiletime) warning. Additionally I don't have any specific concrete
> suggestion for a plan of exactly what syntax these would use.
>
> I just feel that the earlier we get that reservation in, the sooner in
> the future we can start to think about actually using it.
>
>
> Thoughts?

As much as I appreciate the sentiment behind this, I’d prefer syntax 
which doesn’t break legacy code.

[I’ve just waded through a large legacy code base with a lot of regexps, 
escaping ‘{’ characters in regexps because they are now fatal with the 
distributed Perl on RHEL8.]




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