http://www.perlmonks.org?node_id=267642


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.

Replies are listed 'Best First'.
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.