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 开发者_StackOverflow中文版$b
It should be possible to do something like this
print ??? function
This works:
sub test { return (1,2) }
print ((test)[1]); # Returns 2
This also works:
print +(func())[1], "\n";
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.
精彩评论