in reply to Is undef equal to zero

If the type of a value isn't the type called for, Perl automatically converts the value to the appropriate type. undef gets converted to zero when a number is expected, such as for the operand of the numerical equality operator (==).

use strict; use warnings; my $undef; my $non_numeric_str = 'abc'; print "it's 0\n" if $undef == 0; print "it's 0\n" if $non_numeric_str == 0;
Use of uninitialized value in numeric eq (==) at script.pl line 7. it's 0 Argument "abc" isn't numeric in numeric eq (==) at script.pl line 8. it's 0