Perl::...ignAref(3pm)
π NAME π
Perl::Critic::Policy::Plicease::ProhibitArrayAssignAref β bestie, this is a Perl::Critic policy, and its whole vibe is: don't assign an anonymous arrayref to an array. That's it. That's the policy. (It lives in section 3pm, and yes the page header is abbreviated as Perl::...ignAref(3pm) because manpages love to be dramatic and truncate. π)
β¨ VERSION β¨
version 100.00
π¦ DESCRIPTION π¦
Okay so, first things first: this policy is a fork of Perl::Critic::Policy::ValuesAndExpressions::ProhibitArrayAssignAref. The glow-up? It differs from the original by not having a dependency on List::MoreUtils. Slay. But also β and I have to be honest with you β it is unfortunately still licensed as GPL3. π We love a freedom-respecting queen but we also love permissive licensing, y'know?
So what does it actually do? It asks you, politely but firmly, not to assign an anonymous arrayref to an array:
@array = [ 1, 2, 3 ]; # bad
The idea (and it's a good idea, no cap) is that it's rather unclear whether an arrayref is intended, or whether you might have meant to write a list like:
@array = ( 1, 2, 3 );
This policy is filed under the "bugs" theme (see "POLICY THEMES" in Perl::Critic) β like, for the chance that [] is a mistake, and since even if it's correct, it will likely make anyone reading it wonder. It's giving β¨confusionβ¨ and we simply cannot have that in the group chat.
A single arrayref can still be assigned to an array, but you gotta use parens to make it clear:
@array = ( [1,2,3] ); # ok
Dereferences or array and hash slices (see "Slices" in perldata) are recognised as an array target and treated similarly, bestie:
@$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 πΈ
Not me needing to clarify this: this policy is not a blanket requirement for () parens on array assignments. It's normal and unambiguous to have a function call or grep etc. without parens. Lowkey iconic behaviour, actually.
@array = foo(); # ok
@array = grep {/\.txt$/} @array; # ok
The only likely problem from lack of parens in such cases is that the , comma operator has lower precedence than = (see perlop), so something like
@array = 1,2,3; # oops, not a list
actually means
@array = (1);
2;
3;
π Bestie. That's not a list. That's three statements wearing a trench coat.
Normally the remaining literals in void context provoke a warning from Perl itself, so at least Perl is also side-eyeing you.
An intentional single element assignment is quite common as a statement, for instance:
@ISA = 'My::Parent::Class'; # ok
And for reference, the range operator precedence is high enough:
@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
The qw form gives a list too:
@array = qw(a b c); # ok
π SEE ALSO π
Perl::CriticPerl::Critic::Policy::ValuesAndExpressions::ProhibitArrayAssignAref
π HOME PAGE π
<https://github.com/uperl/Perl-Critic-Policy-Plicease-ProhibitArrayAssignAref>
π COPYRIGHT π
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde
Perl-Critic-Policy-Plicease-ProhibitArrayAssignAref 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-Policy-Plicease-ProhibitArrayAssignAref 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-Policy-Plicease-ProhibitArrayAssignAref. If not, see <http://www.gnu.org/licenses>.
π AUTHOR π
- Original author: Kevin Ryde
- Current maintainer: Graham Ollis
<plicease@cpan.org>
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2011-2021 by Kevin Ryde.
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007
And that's the whole page, bestie β this doc was served up by perl v5.40.1, dated 2025-03-20, and that footer was literally its little signature at the bottom of the page. Go forth and parenthesise responsibly. π
β¨
π¦ where this page comes from
- debian trixie: libperl-critic-policy-plicease-prohibitarrayassignaref-perl 100.00-2 Β· GPL-3.0-or-later
- ubuntu resolute: libperl-critic-policy-plicease-prohibitarrayassignaref-perl 100.00-2 Β· GPL-3.0-or-later
- ubuntu stonking: libperl-critic-policy-plicease-prohibitarrayassignaref-perl 100.00-2 Β· 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