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 (Deacon) 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