in reply to About the + in front of a hashref that disambiguates from a code block.

When was it first introduced?

I wonder if unary-plus existed before this use came about.

If so, I wonder if it ever numified.

How did people go around the issue before this was introduced?

The ambiguity problem usually come from omitting parens around function calls. The solution is just to add the parens.

map +(3+$_)*4, ... === map( (3+$_)*4, ... )
  • Comment on Re: About the + in front of a hashref that disambiguates from a code block.
  • Download Code

Replies are listed 'Best First'.
Re^2: About the + in front of a hashref that disambiguates from a code block. (unary -)
by tye (Sage) on Oct 24, 2009 at 18:58 UTC

    I'm pretty sure unary plus existed very early in Perl (it makes perfect sense for it to have been included in the first version of the expression grammar). Not only did early unary + not numerify, I verified that in Perl 4 unary + didn't even impose scalar context.

    Now, unary minus actually did numerify in Perl 4. It was early in Perl 5 when unary minus was taught to just prepend '-' when applied to a string. And I think there was a slight delay between that and -(-bar) being taught to yeild '+bar'. There was also some early finagling to make -bar => ... not complain about 'bareword' even under 'use strict;'.

    - tye        

      Not only did early unary + not numerify
      Late unary + doesn't numerify either:
      $ perl -wE 'say +"foo"' foo $
        We know because the question was whether it had always been that way.
Re^2: About the + in front of a hashref that disambiguates from a code block.
by JavaFan (Canon) on Oct 24, 2009 at 16:39 UTC
    I wonder if unary-plus existed before this use came about.
    I'm pretty sure unary plus has been around since perl 1.0.0. I seriously doubt that writing '+1' in perl 1.0.0 resulted in an error. In fact, I've a hard time thinking of a programming language that doesn't have unary plus.