How do I use boolean variables in Perl?

Chad DeShon picture Chad DeShon · Jun 24, 2009 · Viewed 252.1k times · Source

I have tried:

$var = false;
$var = FALSE;
$var = False;

None of these work. I get the error message

Bareword "false" not allowed while "strict subs" is in use.

Answer

Alan Haggai Alavi picture Alan Haggai Alavi · Jun 24, 2009

In Perl, the following evaluate to false in conditionals:

0
'0'
undef
''  # Empty scalar
()  # Empty list
('')

The rest are true. There are no barewords for true or false.