in reply to is it an array?
if (defined($x) && eval { @$x || 1 }) { print "\$x can be used as an array ref (@$x)\n"; } else { print "\$x cannot be used as an array ref\n"; }
You could also use Scalar::Util's reftype,
if ((reftype($x) || '') eq 'ARRAY') { print "\$x is an array ref (@$x)\n"; } else { print "\$x is not an array ref\n"; }
They are not equivalent. Note the difference in the messages. The first method checks if something can be used as an array reference while the second only checks if it actually is an array reference.
|
|---|