in reply to Re^2: if defined not working
in thread if defined not working
Hey Nick,
The difference really only matters if what you're checking has a false value (that you may not know about, such as when looping through a hash). A false value is still defined:
perl -wMstrict -E 'my $x=0; say $x||1; say $x//2;' 1 0
Update: here's a tiny example that shows that in a larger application, not checking for defined can be an issue when you aren't explicitly looking for truth:
use warnings; use strict; this(arg => 0); sub this { my %args = @_; do_something("if\n") if $args{arg}; do_something("if def\n") if defined $args{arg}; } sub do_something{ print shift; }
|
|---|