Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to determine if an array contains an undef value?

by Laurent_R (Canon)
on Jan 04, 2015 at 16:40 UTC ( [id://1112116]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1112116]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-24 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found