develooper Front page | perl.perl5.porters | Postings from March 2021

Re: Perl feature wish: quote-word array-ref operator

Thread Previous | Thread Next
From:
Smylers
Date:
March 10, 2021 07:35
Subject:
Re: Perl feature wish: quote-word array-ref operator
Message ID:
20210310073526.GA20907@stripey.com
Eric Wong writes:

> One thing that is AFAIK conflict-free could be using a suffix modifier
> (similar to regexp modifiers):
> 
> 	qw[ a b c ]r

That's true, but is way harder to read: the gap between the [ and ] can
be massive; not knowing what you're assigning until you get to the end
of it doesn't make it easy to glance at the code.

Yes, there's precedence in // and s/// modifiers, but some of those can
also cause ‘mental reparsing’ like that. (Note Perl 6 moved the
modifiers to the front, like s:i//.) And generally those modifiers don't
fundamentally change the type of what's being returned as much as this
would.

Avoiding conflicts is nice, but if it results in compromised syntax,
we're then stuck with that syntax for ever.

I would definitely use qa[...] often, because it makes code cleaner than
[qw<...>] and straightforward to see what's going on. I don't think I'd
bother to use qw[...]r; if anything, that makes things less clear,
hiding the difference at the end.

Whether there's a conflict or not, we can only use the new syntax if
running on a sufficiently new version of Perl. It makes sense to declare
that with use v5.$n, ensuring any lower versions fail early with a clear
message. And the use VERSION statement will enable relevant features —
so the resulting code will be the same whether the use is just declaring
the minimum version for qa to work or actively introducing qa as a
change.

Smylers



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