On 10/15/07, Michael Barto <[EMAIL PROTECTED]> 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. snip
Perl 5 does not have a boolean type. Perl considers the following things as false: any number that is equivalent to 0 (0.0, 0e0, etc.), the string '0', the empty string, undef, or an empty list ( i.e. ()). Anything else is considered true. Note that the string "0e0" which evaluates in a numeric context to 0 is not false, but the number 0e0 is false. In general the values 1 and 0 are used just like they are in C. #!/usr/bin/perl use strict; my @a = (undef, 0, 0.0, 0e0, '', "0e0", "0 but true", 1, "foo"); print "() is ", ( () ? 'true' : 'false' ), "\n"; for my $val (@a) { print "[$val] is ", ($val ? 'true' : 'false'), "\n"; }