Hi AnomalousMonk,
defined returns '' (the empty string; false) or 1 (true)
To be even more specific, Perl has a "special" value for "false" - see Truth and Falsehood.
The difference between an empty string and the special "false" value:
$ perl -wMstrict -le 'my $x=""; print 3+$x;' Argument "" isn't numeric in addition (+) at -e line 1. 3 $ perl -wMstrict -le 'my $x=!!""; print 3+$x;' 3 $ perl -wMstrict -le 'my $x=defined(); print 3+$x;' 3
And looking even more closely with Devel::Peek:
$ perl -MDevel::Peek -e 'my $x=undef; Dump($x)' SV = NULL(0x0) at 0x25ea5f8 REFCNT = 1 FLAGS = () $ perl -MDevel::Peek -e 'my $x=0; Dump($x)' SV = IV(0x22ae518) at 0x22ae538 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 0 $ perl -MDevel::Peek -e 'my $x=""; Dump($x)' SV = PV(0xa3e70) at 0xa390e8 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0xa398f0 ""\0 CUR = 0 LEN = 10 COW_REFCNT = 1 $ perl -MDevel::Peek -e 'my $x=defined(); Dump($x)' SV = PVNV(0x3f230e0) at 0x3fe6108 REFCNT = 1 FLAGS = (IOK,NOK,POK,pIOK,pNOK,pPOK) IV = 0 NV = 0 PV = 0x3f6a860 ""\0 CUR = 0 LEN = 10
Regards,
-- Hauke D
Update 2019-08-17: Updated the link to "Truth and Falsehood".
In reply to Re^3: "defined" function fails to evaluate expression; feature or fault?
by haukex
in thread "defined" function fails to evaluate expression; feature or fault?
by w8lle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |