Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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 cooling their heels in the Monastery: (3)
As of 2015-07-06 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls