Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Answer: Like in hashes, do we have something like exists in arrays as well.

( #1015195=categorized answer: print w/ replies, xml ) Need Help??

Q&A > arrays > Like in hashes, do we have something like exists in arrays as well. contributed by SuicideJunkie

use strict; use warnings; my @stuff = (0,1, undef); for (0..3) { print "Element $_ : " . (!exists ($stuff[$_]) ? 'Does not exist' : !defined ($stuff[$_]) ? 'is Undef' : "is '$stuff[$_]'") . "\n"; }
Gives:
>perl test.pl Element 0 : is '0' Element 1 : is '1' Element 2 : is Undef Element 3 : Does not exist

Comment on Answer: Like in hashes, do we have something like exists in arrays as well.
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2015-04-27 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who makes your decisions?







    Results (501 votes), past polls