in reply to Re: How do I test if an array is empty or not?
in thread How do I test if an array is empty or not?

What your code is trying to do is extracting the undefined values (or rather, the indices) from the array - which is a different question. However, your first code fragment not only finds the indices with undefined values, but anything that is 0 in numeric context, which includes 0, the empty string and the undefined value.

Your second code fragment is correct, but it can be written in a more Perlesque way:

my @empties = grep {!defined $array [$i]} 0 .. $#array;

As for the question, just use the array in scalar context. It's empty if the array is 0 in scalar context.

Abigail