Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: [Solved] Pick a single item from a sub's return list

by Not_a_Number (Prior)
on Oct 31, 2015 at 12:16 UTC ( [id://1146572]=note: print w/replies, xml ) Need Help??


in reply to [Solved] Pick a single item from a sub's return list

Alternatively, return a reference:

sub givelist { [ 1 .. 10 ] } say givelist()->[ 2 ];

Update: In fact, if the sub is declared before it's called (as above), the call can be simplified to:

say givelist->[ 2 ];

Replies are listed 'Best First'.
Re^2: [Solved] Pick a single item from a sub's return list
by mr_ron (Chaplain) on Oct 31, 2015 at 13:53 UTC

    You don't really need to change the function to use a reference based solution.

    use Modern::Perl; sub givelist { return 'a' .. 'c'; } say [givelist()]->[1];
    Ron

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-23 07:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found