in reply to Re: "defined" function fails to evaluate expression; feature or fault?
in thread "defined" function fails to evaluate expression; feature or fault?

Not that it makes any difference in this case, but defined returns  '' (the empty string; false) or  1 (true):

c:\@Work\Perl>perl -wMstrict -le "print 'perl version ', $]; ;; print 'undefined A: >', defined(), '<'; print 'undefined B: >', defined(undef), '<'; print 'defined: >', defined(42), '<'; " perl version 5.008009 undefined A: >< undefined B: >< defined: >1< perl version 5.014004 undefined A: >< undefined B: >< defined: >1<


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: "defined" function fails to evaluate expression; feature or fault?
by haukex (Archbishop) on Jan 27, 2017 at 07:44 UTC

    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:

    Regards,
    -- Hauke D

    Update 2019-08-17: Updated the link to "Truth and Falsehood".

Re^3: "defined" function fails to evaluate expression; feature or fault?
by stevieb (Canon) on Jan 26, 2017 at 21:13 UTC

    Yep, I caught that after doing some testing, and had updated my reply (at least I thought I fixed it all).

    Thanks for the heads-up, as if someone is expecting a zero and is getting the empty-string type false instead, it could cause head-scratching.