I think in the more newer languages, they have implemented true booleans. Perl is kind of old school. Pascal defines them as a grandfather of languages. Therefore as one migrates the languages to a higher levels (e.g. Perl[n]), they all will end up with a boolean data type. Therefore, I think the $true and $false is a more consistent method in a multiple languages environments (particularly doing web things [Java and _javascript_] for a consistent set of rules across the board. Thanks for your input.

[EMAIL PROTECTED] wrote:

On Oct 15, 2007, at 11:25 PM, Gary Blackburn wrote:


On Oct 15, 2007, at 4:27 PM, Michael Barto wrote:

As both Java and _javascript_ both have a 'true' and 'false' or Boolean data type, is there any interest in evolution of Perl to have a true Boolean. Or what is the preferred method to do this in Perl. The "C" programmers want me to use "0"'s and "1"'s.

In my experience the most common convention is to use undef and 1 as your boolean values, as in:

my $is_scared;    # is_scared is initially set to undef, which evaluates as "false"

if ($monsters_under_my_bed) {
    $is_scared = 1;
}

Yeah, it's probably bad karma to use "undef" when you mean "0" but this approach is very perl-ish, easy to read, and even recommended by Damian Conway in his "Perl Best Practices" book (page 40... just checked. :-D)

You can, if you really want to, do this:

my $true = 1;
my $false;

Still, it is not much of a substitute for knowing what exactly is _inside_ your variable and testing it to make sure. Plus, boolean values are un-perlish. Look at this for example:

if ($var) {
   print "Yep!";
} else {
   print "Nep!";
}

That is perlish, testing if $var is defined and doing some thing based on that. You can of course make it clearer with

if ( defined ($var))

But to be really perly and terse, this is the idiom:

print "Yep" if ($var);

    Jeremiah


--

Michael Barto
Software Architect

LogiQwest Circle
LogiQwest Inc.
16458 Bolsa Chica Street, # 15
Huntington Beach, CA  92649
http://www.logiqwest.com/

    [EMAIL PROTECTED]
Tel:  714 377 3705
Fax: 714 840 3937
Cell: 714 883 1949

'tis a gift to be simple
This e-mail may contain LogiQwest proprietary information and should be treated as confidential.

Reply via email to