in reply to Getting single element from an array
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
English is not my mother tongue.
Les tongues de ma mère sont "made in France".
Les tongues de ma mère sont "made in France".
|
---|
In Section
Seekers of Perl Wisdom