Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: defined defined -- Bug or "Feature"?

by dsheroh (Prior)
on Dec 24, 2015 at 08:39 UTC ( #1151104=note: print w/replies, xml ) Need Help??


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

two defined's reverses the logic of the expression
No, it doesn't reverse the logic. It's always true, regardless of the single defined's result:
$ perl -E 'say ((defined $x) ? "defined" : "undef")' undef $ perl -E 'say ((defined defined $x) ? "defined" : "undef")' defined $ perl -E '$x = 1; say ((defined $x) ? "defined" : "undef")' defined $ perl -E '$x = 1; say ((defined defined $x) ? "defined" : "undef")' defined
This is because, as stated in previous comments, the first (rightmost) defined will always return a defined result, so the second (leftmost) defined always receives a defined input value.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1151104]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2020-01-27 21:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?