What's the history of the + in front of a hashref that disambiguates from a code block?
I would like to r开发者_Python百科ead a little more about the + that is usually put in front of a hashref that helps to disambiguate from a code block.
When was it first introduced?
Who first introduced it (recommended it)?
How did people go around the issue before this was introduced?
Any trivia or notes that comes to mind while using this syntax?
The specific case of disambiguating a codeblock from the anonymous hashref constructor can't be older than the anonymous hashref constructor, which was added with Perl 5.0 back in 1993-4. Before then the problem didn't exist.
But the "unary plus" has been around for longer -- since Perl 4 at least (it wasn't there in Perl 1 but it could have been added any time in the intervening few years, as far as my knowledge goes). It's always done the same thing, forcing its RHS to be evaluated as a term rather than anything else that might make sense in context, and distinguishing, for example:
print (1 + 2), 42; # Does nothing useful with 42!
from
print +(1 + 2), 42; # Prints 3 and 42.
精彩评论