Boolean values: Difference between revisions

Content added Content deleted
Line 537: Line 537:


<lang perl>my $x = 0.0;
<lang perl>my $x = 0.0;
my $true_or_false = $x ? 'true' : 'false'; # false
my $true_or_false = $x ? 'true' : 'false'; # false</lang>
</lang>
or
or
<lang perl>my $x = 1; # true
<lang perl>my $x = 1; # true

my $true_or_false;
my $true_or_false;

if($x){
if ($x) {
$true_or_false = 'true';
$true_or_false = 'true';
}else{
$true_or_false = 'false';
}
}
else {
</lang>
$true_or_false = 'false';
}</lang>
The values in Perl that are false are: <tt>0</tt> (as a number (including <tt>0.0</tt>), or as the string <tt>'0'</tt>, but '''not''' the string <tt>'0.0'</tt>), the empty string <tt><nowiki>''</nowiki></tt>, the empty list <tt>()</tt>, and <tt>undef</tt>. Everything else is true. See [http://perldoc.perl.org/perlsyn.html#Truth-and-Falsehood perlsyn].
The values in Perl that are false are: <tt>0</tt> (as a number (including <tt>0.0</tt>), or as the string <tt>'0'</tt>, but '''not''' the string <tt>'0.0'</tt>), the empty string <tt><nowiki>''</nowiki></tt>, the empty list <tt>()</tt>, and <tt>undef</tt>. Everything else is true. See [http://perldoc.perl.org/perlsyn.html#Truth-and-Falsehood perlsyn].