[Melbourne-pm] Referencing an item in a list

Bradley Dean bjdean at bjdean.id.au
Sun Mar 26 20:34:27 PST 2006


Ahar! thanks folks...

> Try:
>
> 	my $third_member = (gimme_an_array())[2];

In fact - I had done that, but with a twist...

Here's what I was testing (though not, for some reason, what I put in my
email as an example):

 sub gimme_an_array { return (1,2,3,4,5,6); }
 print gimme_an_array()[2];

The approach emailed to me by a couple of folk worked for my example, ie:

 $third_member = (gimme_an_array())[2];

But it turns out (bring on printf parameter parsing wierdness I say) that
I needed another set of parens (just keep adding them until something
works could be a moral here... :)

 print ((gimme_an_array())[2]);

Cheerio,

Brad

-- 
Bradley Dean ... 平静
Software Engineer - http://bjdean.id.au/
Email: bjdean at bjdean.id.au Mobile: +61-413014395
AICSA - webmaster at aicsa.org.au - http://www.aicsa.org.au/
ICICLES Ski Club - webmaster at icicles.com.au - http://www.icicles.com.au/


More information about the Melbourne-pm mailing list