in reply to How to determine if an array contains an undef value?

Hi,

your @b array is not empty, it has one element which happens to be undef. If you run something like:

print scalar @b;
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.

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

    Hello Laurent_R ,

    Thank you for your time and effort reading and replying to my question. Initially I thought that undef means empty but now it makes more sense undef can be a possition reserved but currently undefined.

    Again thank you for your time and effort.

    Seeking for Perl wisdom...on the process of learning...not there...yet!