Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: defined ? to be : not

by bulk88 (Priest)
on Jun 18, 2012 at 06:32 UTC ( [id://976767]=note: print w/replies, xml ) Need Help??


in reply to defined ? to be : not

Undef is a value, and one particular unique value, it is not a classification and it has nothing to do with bool/truth hood evaluation. Because its printable form is empty string, undef is false. In some systems, -1 is a "false" too (not in perl). Truthhood has to do with flow control. Undef is best used as a unique flag that can mean, error or no data, to separate empty string/0 from error or no data condition, 0 is valid data some times. Undef can't be stored to a file. Falsehood can be stored to a file.

Replies are listed 'Best First'.
Re^2: defined ? to be : not
by Anonymous Monk on Jun 18, 2012 at 06:49 UTC

    Undef .. and it has nothing to do with bool/truth hood evaluation...

    sorry, but you failed to get there :)

    By your own explanation undef evaluates to false in boolean contexts, so yes, it has to do with bool/truth hood evaluation -- and it most certainly can be stored to a file

Re^2: defined ? to be : not
by Don Coyote (Hermit) on Jun 18, 2012 at 07:29 UTC

    Using definedness for flow control is one reason why I felt it would be suitable to use in the ternary operator example. I have also seen this used in cgi.pm where the ternary queries if the value is a reference as the method expects and proceeds accordingly.

    An example of using undefinedness as a control flow can be seen in this node where I help a fellow monk with identifying and then filling initialised array indexes. Trying to edit HoAoA entries. This does not use ternary condition syntax.


    Coyote

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-24 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found