[Chicago-talk] Using "@" to reference element in array

Kent Cowgill kent at c2group.net
Thu Oct 1 15:00:59 PDT 2009

On Oct 1, 2009, at 4:42 PM, Jay Strauss wrote:

> Hi,
> I just got a script at work where the writer used:
> my @array = qw[adf af a adf asdfd];
> print @array[2];
> And it works!!

You must not have warnings turned on.

@array[ @indices ] is a valid way to produce a slice of array values,  
but when there's only one index, the @ sigil doesn't make much sense.   
And when you have warnings turned on, perl tells you that it doesn't  
make sense:

Scalar value @array[2] better written as $array[2] at <filename> line  
<blah blah>.

Kent Cowgill                                     kent at c2group.net

http://kentcowgill.org/blog           http://youtube.com/kcowgill
http://kentcowgill.org/photos   http://flickr.com/people/kcowgill

More information about the Chicago-talk mailing list