Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: What is true and false in Perl?

by ambrus (Abbot)
on Apr 07, 2005 at 19:30 UTC ( #445846=note: print w/ replies, xml ) Need Help??


in reply to What is true and false in Perl?

undef # evaluates to "" so it's false -- note, you may get a warni +ng "use of uninitialized value if you are using -w

I belive you can not get such a warning, an undefined value is always false without any warning when interpreted as a boolean.

From perlsyn, section Declarations (it's so well hidden):

A variable holds the undefined value ("undef") until it has been assigned a defined value, which is anything other than "undef". When used as a number, "undef" is treated as 0; when used as a string, it is treated as the empty string, ""; and when used as a reference that isn't being of an uninitialized value whenever you treat "undef" as a string or a number. Well, usually. Boolean contexts, such as
my $a; if ($a) {}
are exempt from warnings (because they care about truth rather than definedness).


Comment on Re: What is true and false in Perl?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-11-01 00:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (226 votes), past polls