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

On TRUE and FALSE

by merlyn (Sage)
on Jun 20, 2003 at 16:37 UTC ( #267642=note: print w/ replies, xml ) Need Help??


in reply to Code to solve the "matrix formation" puzzle

use constant TRUE => 1; use constant FALSE => 0;
Declaring such constants in Perl is generally agreed to be a Bad Idea. The return value of many "true" values in Perl will generally not be equal to your "TRUE". And the return values of some "false" values is undef, which will only noisily be equal to your "FALSE" (when warnings are enabled).

Just use the truth and falsehood tests within Perl as designed. Don't invent a data type or constant that doesn't exist.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.


Comment on On TRUE and FALSE
Download Code
Re: On TRUE and FALSE
by Rhose (Priest) on Jun 20, 2003 at 17:04 UTC
    Good point.

    While I never use these constants for anything other than setting variables I declare, it would be easy to use them otherwise. I started this habit when I was first learning perl as a way of distinguishing "logical" and "numerics" in my code and for setting "logical" options in some modules (like DBI).

    For example:

    $gDBHandle = DBI->connect ( 'dbi:Oracle:' . ORATNS, ORAUSER, ORAPASS, { AutoCommit => FALSE, PrintError => FALSE, RaiseError => FALSE, } ) || die 'Could not connect to Oracle ['.$DBI::errstr.' - '.$DBI::er +r.']';
    This just helped me remember I was turning "off" those options instead of setting some "numeric" to zero.

    Thank you for the suggestion.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-09-15 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (145 votes), past polls