What is the story + before the hash file that disambiguates the code block?

I would like to read a little more about +, which is usually placed in front of the hash file, which helps to remove the ambiguity from the code block.

  • When was it first introduced?

  • Who first introduced it (recommended)?

  • How did people get around the problem before it was introduced?

  • Any little things or notes that come to mind when using this syntax?

+5
source share
1 answer

The specific case of eliminating incorrect code from the anonymous hashref constructor cannot be older than the anonymous hashref constructor, which was added with Perl 5.0 back in 1993-4. There was no problem before that.

But the β€œunary plus” has been around longer - since Perl 4 at least (it was not in Perl 1, but it could be added at any time in a few years, as far as I know). He always did the same, causing his RHS to be evaluated as a term, and not anything else that might make sense in the context, and distinguish, for example:

print (1 + 2), 42; # Does nothing useful with 42! 

from

 print +(1 + 2), 42; # Prints 3 and 42. 
+9
source

Source: https://habr.com/ru/post/906153/


All Articles