Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask


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.

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

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://267642]
[Corion]: Meh, stupid people are associated with every president
[Corion]: (or presidential candidate)
[Corion]: And if you only have two candidates, you can expect some of the stupid people to make the "right" choice by chance ;)
[erix]: I think it's a little worse this time :)
[Discipulus]: yes; even broken clock show the right time twice a day

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2017-01-24 08:38 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (203 votes). Check out past polls.