How to check for an array reference in Perl
So you've got a Perl
$variable. Can we use it as an array or hash reference? If you do an online search for possible solutions, you'll find a number of suggestions, most of them wrong.
TL;DR: checking if
ref $variable eq 'ARRAY' is almost always a bug. Depending on your use case, you want:
reftype $variable eq 'ARRAY'from Scalar::Util as a check for physical array references, or
_::is_array_ref $variablefrom my module Util::Underscore as a check for logical array references.