Boolean values: Difference between revisions

Content added Content deleted
Line 535: Line 535:


=={{header|Perl}}==
=={{header|Perl}}==

<lang perl>my $x = 0.0;
my $true_or_false = $x ? 'true' : 'false'; # false
</lang>
or
<lang perl>my $x = 1; # true
my $true_or_false;
if($x){
$true_or_false = 'true';
}else{
$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].