defined
The defined function in Perl checks if the given value is anything but undef
examples/defined.pl
use strict; use warnings; use 5.010; my $x; my $y = 0; sub func { return; } my $z = func(); say defined $x ? 'defined' : 'not defined'; # not defined say defined $y ? 'defined' : 'not defined'; # defined say defined $z ? 'defined' : 'not defined'; # not defined say defined $z ? 'defined' : 'not defined'; # not defined say defined &func ? 'defined' : 'not defined'; # defined say defined &other ? 'defined' : 'not defined'; # not defined
defined means it is NOT undef
not defined means it is undef
Being "false" or "true" have different meaning than being "defined" or "not defined".
Published on 2021-03-23
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post