Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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 ( #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.
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 (Pope) 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 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.

      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 $

Log In?
Username:
Password:

What's my password?
Create A New User
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? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2014-07-29 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (216 votes), past polls