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 16:36
Subject:
Re: Perl feature wish: quote-word array-ref operator
Message ID:
20210305173616.473ee24e@pc09.procura.nl
On Fri, 5 Mar 2021 16:05:29 +0000, Philip R Brenan
<philiprbrenan@gmail.com> wrote:

> Even better :
> 
> use autoref; my $a = qw(a b c);  is_deeply $a, ['a','b','c'];
> 
> which opens the way to making sigils optional by making % and @
> unnecessary.

Where the original suggestion - to me - makes perfect sense, and I
would use it, this seems - to me - counter-productive (so not better
but worse) as my eyes now have to re-thing *every* line of code in
the file to see if I still understand what is happening.

it hides possible flaws and typoes and making % and @ unnecessary is
most likely a new source for new problems.

The *only* possible positive point in your suggestion is that is is
only in scope when using a module, which I would never do, so I will
stay safe.

Just my opinion, which is based on "even better"

> On Fri, Mar 5, 2021 at 8:47 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 ];
> >
> > 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