Reputation: 43427
I'm looking for a one-liner that lets me grab the second return value from a subroutine.
Rather than this:
($a,$b)=function;
print $b
It should be possible to do something like this
print ??? function
Upvotes: 0
Views: 154
Reputation: 234795
This works:
sub test { return (1,2) }
print ((test)[1]); # Returns 2
This also works:
print +(func())[1], "\n";
Upvotes: 6
Reputation: 701
assuming that function() returns a list, then using a slice like the poster above suggested works just fine. If it returns an array reference, then you need to access it appropriately, for instance (@{function()})[1] to dereference the aref and then slice it.
Upvotes: 0