boolean
boolean - Boolean support for Perl
use boolean;
do &always if true;
do &never if false;
and:
use boolean ':all';
$guess = int(rand(2)) % 2 ? true : false;
do &something if isTrue($guess);
do &something_else if isFalse($guess);
Most programming languages have a native Boolean data type.
Perl does not.
Perl has a simple and well known Truth System. The following scalar values are false:
$false1 = undef;
$false2 = 0;
$false3 = 0.0;
$false4 = '';
$false5 = '0';
Every other scalar value is true.
This module provides basic Boolean support, by defining two special
objects: true and false.
Version 0.20 is a complete rewrite from version 0.12. The old version used XS and had some fundamental flaws. The new version is pure Perl and is more correct. The new version depends on overload.pm to make the true and false objects return 1 and 0 respectively.
The "null" support found in 0.12 was also removed as superfluous.
When sharing data between programming languages, it is important to support the same group of basic types. In Perlish programming languages, these types include: Hash, Array, String, Number, Null and Boolean. Perl lacks native Boolean support.
Data interchange modules like YAML and JSON can now use boolean to
encode/decode/roundtrip Boolean values.
This module defines the following functions:
boolean::true if the scalar passed to it is the
boolean::true object. Returns boolean::false otherwise.
boolean::true if the scalar passed to it is the
boolean::false object. Returns boolean::false otherwise.
boolean::true if the scalar passed to it is the
boolean::true or boolean::false object. Returns boolean::false
otherwise.
By default this module exports the true and false functions.
The module also defines these export tags:
Ingy döt Net <ingy@cpan.org>
Copyright (c) 2007, 2008. Ingy döt Net.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html