Perl::...ignAref(3pm)
π Perl::...ignAref π
okay bestie, so this page lives in the User Contributed Perl Documentation section of the manual, and it's giving Perl::Critic::Policy::ValuesAndExpressions::ProhibitArrayAssignAref. yes that name is a whole mouthful, we know, slay anyway β¨
πΈ NAME πΈ
Perl::Critic::Policy::ValuesAndExpressions::ProhibitArrayAssignAref β bestie please do NOT assign an anonymous arrayref to an array. that's the whole thing. that's the vibe. π
π¦ DESCRIPTION π¦
so this policy is part of the Perl::Critic::Pulp add-on, and its one (1) job is gently asking you not to assign an anonymous arrayref to an array:
@array = [ 1, 2, 3 ]; # bad
like⦠why. the whole point is that it's lowkey unclear whether you actually meant an arrayref, or whether you were trying to write a plain old list like
@array = ( 1, 2, 3 );
and got lost along the way π
this policy is filed under the "bugs" theme (peep "POLICY THEMES" in Perl::Critic) because there's a real chance that [] is just a mistake β and even when it's correct, it's gonna make anyone reading your code stop and wonder, which is not the main character energy we're going for.
good news though!! a single arrayref can still be assigned to an array β you just need parens to make it crystal clear π
@array = ( [1,2,3] ); # ok
dereferences, plus array and hash slices (see "Slices" in perldata), all count as an array target and get treated exactly the same way:
@$ref = [1,2,3]; # bad assign to deref
@{$ref} = [1,2,3]; # bad assign to deref
@x[1,2,3] = ['a','b','c']; # bad assign to array slice
@x{'a','b'} = [1,2]; # bad assign to hash slice
π List Assignment Parens π
okay important clarification bestie: this policy is NOT a blanket "you must use () parens on every array assignment" rule. no ma'am. it's completely normal and unambiguous to have a function call, or grep, etc., without parens.
@array = foo(); # ok
@array = grep {/\.txt$/} @array; # ok
the only likely problem from skipping parens in cases like those is that the , comma operator has lower precedence than = (check perlop), so something like
@array = 1,2,3; # oops, not a list
actually means
@array = (1);
2;
3;
π and normally those leftover literals sitting in void context will provoke a warning from Perl itself, so at least it's not silent.
an intentional single element assignment as a statement is super common though, for instance
@ISA = 'My::Parent::Class'; # ok
and for reference: the range operator's precedence is high enough, so you're fine there too
@array = 1..10; # ok
but of course parens ARE needed if you're concatenating some disjoint ranges with the comma operator:
@array = (1..5, 10..15); # parens needed
and the qw form gives you a list too, no stress
@array = qw(a b c); # ok
π SEE ALSO π
Perl::CriticPerl::Critic::Pulp
π HOME PAGE π
http://user42.tuxfamily.org/perl-critic-pulp/index.html
π COPYRIGHT π
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde
Perl-Critic-Pulp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Perl-Critic-Pulp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Perl-Critic-Pulp. If not, see http://www.gnu.org/licenses.
and that's the whole page, bestie!! π«Ά this one came from perl v5.40.1 and got timestamped 2025-10-21 β it's the Perl::...ignAref(3pm) page, mwah, go write some unambiguous array assignments π
β¨
π¦ where this page comes from
- ubuntu resolute: libperl-critic-pulp-perl 100-1 Β· GPL-3.0-or-later
- ubuntu stonking: libperl-critic-pulp-perl 100-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms