SPUG: Interesting bug using 'map'
Ivan Heffner
iheffner at gmail.com
Fri Apr 10 09:25:22 PDT 2009
On Fri, Apr 10, 2009 at 7:46 AM, <seasprocket at gmail.com> wrote:
> On Thu, Apr 9, 2009 at 10:19 PM, Tye McQueen <tyemq at cpan.org> wrote:
>>
>> On Thu, Apr 9, 2009 at 8:52 PM, <seasprocket at gmail.com> wrote:
>>>
> I was wondering myself why assignment to something like @arr[0] invokes list
> context. Just a convention, or perhaps some deeper reason? Maybe it is to
> avoid ambiguities such as @arr[$x..$y] ?
>
You asked for an array slice (list) when you said @arr[0]. If you want
an array element (scalar) use $arr[0]. I believe this is one of the
gotchas called out in Learning Perl, but it has been years since I
looked through that book. BTW, the array slice you asked for happens
to be of length 1, but it is still a slice because you used the @
sigil.
Ivan
More information about the spug-list
mailing list