[Melbourne-pm] (no subject)

Brendon Oliver brendon.oliver at gmail.com
Sun Mar 26 21:29:43 PST 2006


On Monday 27 March 2006 14:35, wigs at stirfried.org wrote:


> > sub gimme_an_array { return (1,2,3,4,5,6); }
> > my $third_member = gimme_an_array()[2];
> >
> > Which is invalid syntax, but I cannot work out the correct syntax....
>
> my $third_member = (gimme_an_array())[2];

Or, if you don't like the extra parens as describe by Paul & Wigs, do it via 
an array ref instead of an array:

sub gimme_an_arrayref { return [1,2,3,4,5,6]; }
my $third_member = gimme_an_arrayref()->[2];

cheers,

- Brendon.

-- 
Pause for storage relocation.

 15:27:47 up 4 days, 23:22,  1 user,  load average: 0.48, 0.37, 0.39



More information about the Melbourne-pm mailing list