Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by PoorLuzer (Beadle)
on Oct 24, 2009 at 10:04 UTC ( [id://803020]=perlquestion: print w/replies, xml ) Need Help??

PoorLuzer has asked for the wisdom of the Perl Monks concerning the following question:

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 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?

  • Comment on About the + in front of a hashref that disambiguates from a code block.

Replies are listed 'Best First'.
Re: About the + in front of a hashref that disambiguates from a code block.
by Anonymous Monk on Oct 24, 2009 at 11:00 UTC
Re: About the + in front of a hashref that disambiguates from a code block.
by ikegami (Patriarch) on Oct 24, 2009 at 16:36 UTC

    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, ... )

      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 $
      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://803020]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-25 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found