Home > Software engineering >  How can I shorten a [ qw( ... ) ] construct in Perl?
How can I shorten a [ qw( ... ) ] construct in Perl?

Time:03-24

Perl's quote-like operator qw() creates a word list from barewords, while square brackets [] can be used to create references to anonymous arrays. Now, I was wondering if Perl provides a way to somehow abbreviate this:

my $aref = [qw( a b c )];

using something like a non-existent qa() operator:

my $aref = qa( a b c );

I've been using qw() and [] together quite a lot recently, and all I want is to reduce cluttering.

Note: This is not what I'm looking for:

my @a = \( qw( a b c ) );

CodePudding user response:

Not core Perl, but check out Syntax::Feature::Qwa

CodePudding user response:

No, there is no shorter way with core Perl to express:

my $aref = [qw( a b c )];
  • Related