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

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

Thread Previous | Thread Next
From:
H.Merijn Brand
Date:
March 5, 2021 08:54
Subject:
Re: Perl feature wish: quote-word array-ref operator
Message ID:
20210305095421.113161bd@pc09.procura.nl
On Fri, 5 Mar 2021 08:48:25 +0000, 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 ];

+1

> 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.
> 
> 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.
> 
> The proposed syntax doesn't currently compile, so maybe this could
> just be added to the language, without an experimental or feature
> guard? Because there's already qwa// on CPAN (see below), I'm
> suggesting qa//.
> 
> I'm not proposing an operator for hashrefs, as I've never wanted one,
> and there's no real evidence of a need for one on CPAN.
> 
> Prior Art on CPAN
> 
> There are a number of modules that provide an operator like this, but
> (a)  I don't want to add a dependency for this syntax, and (b) they
> introduce additional dependencies.
> 
> Syntax::Feature::Qwa defines qwa// (and qwh// and qwk//  for hashes).
> 
> Quote::Ref also add qwa// (and qwh// for hashes)
> 
> Quote::Reference defines qwr// for arrayrefs and qhr// for hashrefs.
> 
> There's also PerlX::QuoteOperator, which lets you define your own
> quote operator.


-- 
H.Merijn Brand  https://tux.nl   Perl Monger   http://amsterdam.pm.org/
using perl5.00307 .. 5.33        porting perl5 on HP-UX, AIX, and Linux
https://tux.nl/email.html http://qa.perl.org https://www.test-smoke.org
                           

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