develooper Front page | perl.perl5.porters | Postings from May 2008

Re: [perl #54974] Strange map {} Behavior When Returning Two Values

Thread Previous
David E. Wheeler
May 28, 2008 12:45
Re: [perl #54974] Strange map {} Behavior When Returning Two Values
Message ID:
On May 28, 2008, at 12:36, A. Pagaltzis via RT wrote:

> Really this should be decided based on whether the closing brace
> is followed by a comma or not, so in some sense this is certainly
> a bug.

Yes, exactly, very well put.

> But my understanding is that the syntactic ambiguity of
> curly braces in Perl is difficult to handle in perl’s ultimately
> yacc-derived (but heavily mutated) parser, which uses a limited
> lookahead for curlies to work around the fact that this style of
> parser strongly favours tokens with only a single meaning. In
> practice, the heuristic works most of the time and the
> disambiguation cues are easy to employ.

Yes, but this one was so mystifying to me. Now that I know the issue,  
I can fix it, but it took me over an hour to get it to work, and I was  
mystified by the workaround. Your explanation has really helped, of  
course, and I can see why it behaves that way (sort of), but it seems  
pretty bizarre absent that knowledge.

> (You can equivalently disambiguate a hash constructor that gets
> misparsed as a block by prepending a unary plus: `+{ ... }`.
> Within such a block, statements are always a compile error.)

I use the unary plus to disambiguate class method calls in my tests,  

ok +Some::Class->method, 'Call method';

> Someone else will have to tell you whether this is a WONTFIX tho.

I hope not! Thanks for the info, Aristotle, as always.


Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About