SPUG: Interesting bug using 'map'

seasprocket at gmail.com seasprocket at gmail.com
Fri Apr 10 07:46:01 PDT 2009


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:
>
>> map evaluates BLOCK in LIST context
>
>
>
>> But that's ugly -- is there a cleaner way to avoid this problem?
>>
>
> ... map { scalar( ... ) } ...


Okay, duh ... thanks for pointing that out.

>
>
> There are also lots of other ways to get scalar context.  Speaking of bugs,
> I consider the fact that the following doesn't fix the problem (at least not
> in all versions of Perl) to be a Perl bug :)
>
> ... map { ( ... )[0] } ...


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] ?


>
>
> Tye
>



-- 
==========================
2People citizen's network for climate action: http://www.2people.org

Greater Seattle Climate Dialogues: http://www.climatedialogues.org
The Great Warming coalition
==========================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/spug-list/attachments/20090410/be2a8206/attachment.html>


More information about the spug-list mailing list