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

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

Thread Previous | Thread Next
From:
Felipe Gasper
Date:
March 5, 2021 12:09
Subject:
Re: Perl feature wish: quote-word array-ref operator
Message ID:
8650C671-C53A-4DD5-87F5-2E52B80D87EA@felipegasper.com


> On Mar 5, 2021, at 3:48 AM, Neil Bowers via perl5-porters <perl5-porters@perl.org> wrote:
> 
> It would be handy to have a "quote word arrayref operator" in Perl, that combines [] with qw.
> 
> So instead of writing:
> 
>     $a = [ qw/ one two three/ ];
> 
> You could write:
> 
>     $a = qa[ one two three ];

For what it’s worth, I don’t think I’ve ever wanted anything like this. Maybe it’s just me.

> 
> As with qw, you could either use bracketing delimiters, or use the same character:
> 
>     $a = qa/ one two three /;
> 
> But I'd expect most people would use qa[ … ] as it visually reinforces what's going on.
> 
> This reduces line-noise, making code more readable, and the intention clearer.

This assumes a maintainer takes the time to learn *yet* another syntactic variant in Perl--and in one of its more esoteric syntax areas to boot.

The fact of so many ways to do the same thing is, I think, part of what effects Perl’s reputation of being a “write-only” language: a new maintainer has to grok the last author’s syntactic idiosyncrasies in order to do the work. If there are 10 ways to do something, and now we’re adding an 11th, that compounds the problem.

> The quote-word arrayref construct is widely used. For example, as of 16th Feb 2021, 12681 distributions on CPAN (36%) use it either in modules, scripts, tests, or build scripts.

This seems probably the most compelling rationale, but it’s a bit like auto-dereference: how much convenience does this *actually* provide, versus the overhead of adding yet more syntax to the language? (Auto-deref, I know, had other problems, too, as ably laid out in the recent thread on the topic.)

-F
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