This policy is a fork of Perl::Critic::Policy::ValuesAndExpressions::ProhibitArrayAssignAref. It differs from the original by not having a dependency on List::MoreUtils. It is unfortunately still licensed as GPL3.
It asks you not to assign an anonymous arrayref to an array
@array = [ 1, 2, 3 ]; # badThe idea is that it's rather unclear whether an arrayref is intended, or might have meant to be a list like
@array = ( 1, 2, 3 );This policy is under the "bugs" theme (see Perl::Critic/POLICY THEMES) for the chance '[]' is a mistake, and since even if it's correct it will likely make anyone reading it wonder.
A single arrayref can still be assigned to an array, but with parens to make it clear,
@array = ( [1,2,3] ); # okDereferences or array and hash slices (see perldata/Slices) are recognised as an array target and treated similarly,
@$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
| Package Version | Update ID | Released | Package Hub Version | Platforms | Subpackages |
|---|---|---|---|---|---|
| 100.0.0-bp160.1.4 info | GA Release | 2025-01-22 | 16.0 |
|
|