in reply to How to determine if an array contains an undef value?
your @b array is not empty, it has one element which happens to be undef. If you run something like:
it will print 1, which is why, if you evaluate the array in boolean context (... if (@b);) you get a true value and your sentence is printed.print scalar @b;
If you want to check if the array contains at least one defined element, yes, you probably have to do ... if grep { defined($_) } @b; or something similar. You may want something else, though, if your array is large.
Update: corrected a typo.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to determine if an array contains an undef value?
by thanos1983 (Parson) on Jan 04, 2015 at 22:30 UTC |