Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: What is true and false in Perl?

by ambrus (Abbot)
on Apr 07, 2005 at 19:30 UTC ( [id://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).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-19 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found