Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: map syntax bug-a-boo?

by shotgunefx (Parson)
on Nov 30, 2001 at 17:38 UTC ( [id://128620]=note: print w/replies, xml ) Need Help??


in reply to Re: map syntax bug-a-boo?
in thread map syntax bug-a-boo?

Can I ask a silly question? What does the + mean to Perl in these examples. I don't ever recall seeing it ever used in such a way.

-Lee

"To be civilized is to deny one's nature."

Replies are listed 'Best First'.
Re(3) (dmm): map syntax bug-a-boo?
by dmmiller2k (Chaplain) on Nov 30, 2001 at 19:21 UTC

    It's like making explicit the implicit '+' that precedes any non-negative number (think scalar ::= number or string).

    Do you remember, when learning how to format numbers for output (using '%f', '%g', etc.) with printf in C, you had to account for the sign position? It would display as either a hyphen or blank. A blank, however, was analagous to a plus-sign.

    Likewise, on input, non-negative numbers could optionally be expressed with a leading plus-sign. Since scalars (or scalar expressions) may be either numbers or a strings in perl, perl allows this with arbitrary scalar expressions.

    dmm

    
    You can give a man a fish and feed him for a day ...
    Or, you can teach him to fish and feed him for a lifetime
    
Re: Re: Re: map syntax bug-a-boo?
by chipmunk (Parson) on Dec 01, 2001 at 09:39 UTC
    Unary minus negates its operand, either adding a minus sign, or switching a minus sign to a plus sign or vice versa. Unary plus, on the other hand, returns its operand completely unchanged. Why is this useful? It can come in handy when dealing with ambiguous syntax.

    More examples of unary plus:

    print (3-1)*2; # oops! print (...) interpreted as function ... print +(3-1)*2; sub foo { $foo } $h{foo}; # equivalent to $h{'foo'} $h{+foo}; # but maybe you meant $h{foo()}
    See perlop for more on this curious operator.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-20 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found