Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: return +0

by lidden (Curate)
on Nov 27, 2007 at 09:07 UTC ( [id://653176]=note: print w/replies, xml ) Need Help??


in reply to Re^2: return +0
in thread return +0

In that example the + tells perl that the parens are not enclosing the arguments to a function call, so it is parsed correctly.

Replies are listed 'Best First'.
Re^4: return +0
by DrHyde (Prior) on Nov 27, 2007 at 10:36 UTC

    Here's a nice simple example of when you might need to use it:

    $ perl -e 'print (2+3)/5' 5

    How on earth does that print 5? Because it evaluates as "print the result of 2 + 3, then divide print's return value (which is 1 if print worked) by 5, and then do nothing with the result". This is obvious if you stick another print in there:

    $ perl -e 'print print (2+3)/5' 50.2

    which is parsed as:

    print((print(2+3))/5)

      And just to close the logic loop (++DrHyde and lidden, btw), this leading plus helps the parser evaluate all those numbers into a single value before printing.

      $ perl -e 'print +(2+3)/5' 1

      So I assume the author of the code the OP was reading thought there might be some ambiguity and wanted to help the parse out with that return statement.


      I humbly seek wisdom.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found