Say a Perl subroutine returns an array:
sub arrayoutput
{
...some code...
return @somearray;
}
I want to access only a specific arr
Pull off the first argument only via list context:
my ( $wanted ) = array_returning_sub( @args );
TIMTOWTDI with a slice:
my $wanted = ( array_returning_sub( @args ) )[0];
Both styles could be extended to extract the n'th element of the returned array, although the list slice is a bit easier on the eye:
my ( undef, undef, $wanted, undef, $needed ) = array_returning_sub( @args );
my ( $wanted, $needed ) = ( array_returning_sub( @args ) )[2,4];