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

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

Thread Next
From:
Paul "LeoNerd" Evans
Date:
January 14, 2023 14:40
Subject:
Making s:foo:bar: warn "reserved" - contentious idea?
Message ID:
20230114143949.0585853b@shy.leonerd.org.uk
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?

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

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