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

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

Thread Next
Paul "LeoNerd" Evans
January 14, 2023 14:40
Making s:foo:bar: warn "reserved" - contentious idea?
Message ID:
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:;


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

  qq:interpolated string:
  qw:quoted word list:
  qx:executed string:

  qr:regexp literal:
  m:regexp match:
  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.


Paul "LeoNerd" Evans      |  |

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About