print ("adf","ff","f"); # Gladly prints the list print ("adf","ff","f")[1]; #Gives a syntax error
Think to print() as a subroutine: you can write myfunc(...); but myfunc(...)[1]; is wrong.
With a "gift package ( )", perl will be happy: myfunc( (...][1] );
perl -e 'sub myfunc { return @_;}; my @res = myfunc(('a','b','c')[1]);print @res;' OKperl -e 'sub myfunc { return @_;}; my @res = myfunc('a','b','c')[1];print @res;' WRONG
In reply to Re: Getting single element from an array
by brx
in thread Getting single element from an array
by gurpreetsingh13
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |