in reply to if multiple arg return or single fail?

Note that the top level operator in the if() statement is an list-assignment. List-assignment returns the number of items on the right-hand side of the assignment. So only if mysub returns an empty list, the else part will be executed.

Now, you can get the value of $x by using:

if ((my ($x, $y) = mysub ($args))[0]) {
but I don't think there's an easy way to say "mysub returns at least 2 values, or a non-zero value" while at the same time declaring and assigning those values to variables all in one go. But if you take the declaration out:
my ($x, $y); if ((($x, $y) = mysub ($args)) != 1 || !defined($x) || length($x) != 1 + || $x != 0) { do stuff } else { # Triggered on a single 0 do other stuff }
Whether this is the most readable solution, I'm not so sure.

Replies are listed 'Best First'.
Re^2: if multiple arg return or single fail?
by raybies (Chaplain) on Mar 07, 2011 at 17:49 UTC
    Buwahahaha! That's brilliant stuff, Javafan. I've used the (bunch-o-stuff)[0] approach before, but had really thought to use it in that context. Good stuff... Thanks! --Ray