Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Arefs: Testing for Truth:

by Vautrin (Hermit)
on Mar 24, 2004 at 00:43 UTC ( #339261=note: print w/replies, xml ) Need Help??


in reply to Testing for Truth

An array in boolean context is assumed to mean "are there any elements in me" and represents true because it contains 0. Since undefined values, the string "", and 0 (also "0") are false, the 0th element in the array is false.

(defined $foo->[0]) ? print "TRUE\n" : print "FALSE\n";

Should print TRUE. Note that you should use:

use strict; use warnings;

at the top of all your scripts to alert you to things like this in your code. Of course, in this particular instance, there would be no warnings because what you did is supposed to be widely known.


Want to support the EFF and FSF by buying cool stuff? Click here.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2022-05-25 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (90 votes). Check out past polls.

    Notices?