Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Getting single element from an array

by brx (Pilgrim)
on Nov 05, 2012 at 17:31 UTC ( #1002370=note: print w/ replies, xml ) Need Help??


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;' OK

perl -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".


Comment on Re: Getting single element from an array
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002370]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-11-28 03:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (192 votes), past polls