in reply to defined vs null string
defined EXPR defined Returns a Boolean value telling whether EXPR has a value other than the undefined value "undef". If EXPR is not present, $_ is checked.
An interesting thing to notice, is that defined returns nothing if something is undef. But it prints a 1 if defined. Sort of an asymetric boolean. One might expect 0 to be printed, but that return value would be defined, and would screw up the defined function used in more complex logic.
#!/usr/bin/perl use warnings; use strict; print defined (undef) ,"\n"; # prints nothing but a newline my $y = undef; print defined ($y),"\n"; # prints nothing but a newline my $x = ''; print defined ($x), "\n"; # prints a 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: defined vs null string
by jwkrahn (Abbot) on Aug 30, 2011 at 19:50 UTC | |
by zentara (Cardinal) on Aug 30, 2011 at 22:19 UTC |