My understanding is that I can use
if (@array) { print "array not null"; }
to test if all the elements of an array are null. Is there a way I can use this to test a 2 dimensional array?
Essentially you need to loop through the first dimension of the array to find out if any of the sub-arrays contain anything. This works:
use List::Util qw( any );
if (any { @$_ } @array) { print "array not null\n"; }
If you're stuck using an old version of List::Util that doesn't provide any, in this case first will work as a reasonable substitute:
use List::Util qw( first );
if (first { @$_ } @array) { print "array not null\n"; }
Though I think than any better clarifies the intent of the code.
map @$_, @array?any and first are short circuited. Map will loop even if first element is not empty
if (@array)test if array is empty/has no elements. If it has elements and these are undef/null, it will be boolean true.