Hi
I'm perplexed; I'm using CGI to receive a list of parameters, which might arrive under one name or another. So I wrote:
my @things = $q->param('t') or $q->param('things');
I wanted the list of parameters in t, or if that parameter is absent, the ones in things. It's all good if t is present, but fails otherwise, with an empty list. I narrowed it down to the following test case:
sub foo { wantarray ? () : 1; } sub bar { wantarray ? (3, 4) : 3; } my @thingies = foo() or bar(); warn @thingies; # Expected (3,4) here, got () my @thingies = ( foo() ) or ( bar() ); warn @thingies; # Expected (3,4) here too, got ()
I don't understand! If I were using ||, sure, that puts the calls in scalar context; however, with or, why doesn't the first sub get called in list context, return false with the empty list, and let the second sub get called? What am I missing?
Thanks
ViceRaid
update: fixed cut-and-paste mistakio in code results comment, as pointed out by Abigail-II
In reply to Precendence and wantarray puzzling me by ViceRaid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |