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

Re: [OT] Perl feature wish: quote-word array-ref operator Perl5Porters <perl5-porters@perl.org>

Thread Previous | Thread Next
From:
=?UTF-8?Q?Andr=c3=a9_Warnier_=28tomcat/perl=29?=
Date:
March 10, 2021 10:08
Subject:
Re: [OT] Perl feature wish: quote-word array-ref operator Perl5Porters <perl5-porters@perl.org>
Message ID:
d5cffb7d-1be6-1a63-9be7-4d317589f741@ice-sa.com
Hi.
Just an aside.
As mentioned in the past, I am all for the introduction of new features and options and 
operators in perl, if they can be of use to some and make the language look more 
attractive to young people (and they don't break anything that has been working for 20 years).
But as I read the discussion below, I am wondering about the documentation of it in 
perldoc.  Who is going to write this, in a way that is understandable and not off-putting 
for ditto newbies ? Should this not also be a criterium when adding things ?

On 10.03.2021 10:15, Salvador Fandiño wrote:
> On 5/3/21 9:48, Neil Bowers via perl5-porters 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.
> 
> Am I the only one that doens't have a big love for the qw operator?
> 
> I mean, not having to write all these quotes around words is great, but I miss the commas. 
> I don't like either that it is an all or nothing solution. There is no way to escape 
> spaces or to allow interpolations.
> 
> Something I really dislike is using it to initialize hashes, as in...
> 
>    my %h = qw(foo bar doz ber noz cloz);
> 
> Because it is not obvious what is a key and what is a value.
> 
> Other pain point is when you want to create a list including some words and also some 
> variables, as for instance:
> 
>    my @a = (qw(foo bar), $foo, $bar);
> 
> So, while thinking about the qa operator proposed by Neil, it has occurred to me that it 
> doesn't solve most of the issues I have with qw. I would rather prefer having an operator 
> (for instance, "qb") that just creates some kind of bareword context:
> 
>    my @a = qb(hello, world, bye, world);
>    my %h = qb(hello => world, bye => world);
> 
> And also:
> 
>    my @a = qb("hello, world", bye, $world);
>    # equivalent to ("hello, world", "bye", $world)
> 
> And as it is a new operator, we could let it handle [] and {} in special ways:
> 
>    my $aref = qb[hello, world, bye, world];
>    my $href = qb{hello => world, bye => world};
> 
> Does this makes sense?
> 


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