http://www.perlmonks.org?node_id=1151094


in reply to defined defined -- Bug or "Feature"?

defined($x) returns a false, but defined value, so defined(defined($x)) is true.

Dave.

Replies are listed 'Best First'.
Re^2: defined defined -- Bug or "Feature"?
by GrandFather (Saint) on Dec 24, 2015 at 08:00 UTC

    You state that like you know it to be the case, but I couldn't see that behavior described in the documentation. Do you know this from the code?

    Premature optimization is the root of all job security
      The docs say that it returns a boolean value, i.e. a true or false value. It would be surprising for a false value to also be undefined, as you would get 'undefined' warnings if you tried using operators on the results. This shouldn't warn:
      $x = defined($y) ^ defined($z);

      Dave.

      I guess he didn't (guess). It's easily tested...
      print defined( undef ) // 'n/a'; print defined( undef ) || 'n/a'; n/a