in reply to Odd (to me) case of wrongly guessing context
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Odd (to me) case of wrongly guessing context
by choroba (Cardinal) on May 20, 2013 at 22:37 UTC | |
by LanX (Saint) on May 20, 2013 at 23:32 UTC | |
by rjt (Curate) on May 20, 2013 at 23:29 UTC |