What's the history of the + in front of a hashref that disambiguates from a code block?

前端 未结 1 1361
滥情空心
滥情空心 2021-01-19 03:09

I would like to read 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 int

相关标签:
1条回答
  • 2021-01-19 03:49

    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.
    
    0 讨论(0)
提交回复
热议问题