Your problem comes from the combination of the my ... with the defined-or operator. It's an operator precedence issue: put (my ...) in brackets. You can also use the low-precedence or operator, but only if you can guarantee that 0 will never be a valid return.
sub context { wantarray ? (qw/foo bar/) : -1 } my ($not_foo) = context() // say "Whoops"; say $not_foo; (my ($foo) = context()) // say "Whoops"; say $foo; # This works if context() can never return 0 my ($also_foo) = context() or say "Whoops"; say $also_foo;
In reply to Re: Odd (to me) case of wrongly guessing context
by rjt
in thread Odd (to me) case of wrongly guessing context
by ibm1620
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |