Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 imbibing at the Monastery: (11)
As of 2014-12-17 20:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (32 votes), past polls