It's not a feature or bug, it just is :)
defined() returns a bool, (either false/true) when it evaluates something, so when you do this: defined ($x || $y);, it's not doing what you think it does.
Here's an example that illustrates the issue:
perl -wMstrict -E 'my $x = defined $ARGV[5]; say defined $x' 1
Now, $ARGV[5] is not set in any way, but since we're returning the value of the call to $x, $x will most definitely be defined, because it now evaluates to false as the variable was not defined (define() returns false, if something wasn't defined).
You need to call a define on each side of the comparison operator:
my $x = defined $x || defined $y;
...as per your solutions that work. Then, check $x for truth:
die "blah...\n" if ! $x;
...or combined:
die "blech...\n" if ! defined $x || defined $y;
In reply to Re: "defined" function fails to evaluate expression; feature or fault?
by stevieb
in thread "defined" function fails to evaluate expression; feature or fault?
by w8lle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |