Perl (Scripting) - Getting Started with Booleans

by
Jeremy Canfield |
Updated: December 09 2022
| Perl (Scripting) articles
In Perl, the number 0 is use for the false boolean and any number other than 0 is used for the true boolean.
This script will print false.
#!/usr/bin/perl
use strict;
use warnings;
my $boolean = 0;
if ($boolean) {
print "true \n";
}
else {
print "false \n";
}
Whereas this script will print true.
#!/usr/bin/perl
use strict;
use warnings;
my $boolean = 1;
if ($boolean) {
print "true \n";
}
else {
print "false \n";
}
Did you find this article helpful?
If so, consider buying me a coffee over at