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

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

Thread Previous | Thread Next
From:
Eric Wong
Date:
March 10, 2021 05:18
Subject:
Re: Perl feature wish: quote-word array-ref operator
Message ID:
20210310051828.GA29748@dcvr
Neil Bowers via perl5-porters <perl5-porters@perl.org> wrote:
> 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//.

One thing that is AFAIK conflict-free could be using a suffix
modifier (similar to regexp modifiers):

	qw[ a b c ]r

In the above case, "r" would tell the user it's a reference.
Maybe another character can work, too.  One modifier I would
find useful is the ability to enable interpolation (like qq[]),
for arrays, similar to %W() in Ruby:

	my @args = qw[ a b $c d ]i;
	my $args = qw[ a b $c d ]ir;

That would make generating safe argument lists for system() and
similar things easier.

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

(reordered quote)  Another thing I've also sometimes wanted is
native support for ordered hashes(*), prefix tries, or other
dictionary-like structures beyond the built-in unordered hash.
So being able to add modifiers to hashes/hashrefs would be
helpful:

	my $ordered = { foo => 'bar' }o;

Other modifiers could be to use integer values as keys,
case-insensitive keys, etc..


(*) ordered hashes are probably easier for people coming from
    other languages (e.g. Ruby).  I prefer unordered hashes
    remain the default in Perl for space savings.

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