Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^2: ** operator in perl

by Random_Walk (Prior)
on Feb 03, 2009 at 12:55 UTC ( #740976=note: print w/replies, xml ) Need Help??

in reply to Re: ** operator in perl
in thread ** operator in perl

I was puzzled by this one too ...

[me@ptmr]/home/me$ perl -le 'print -2 ** 4 ' # ** binds before - -16 [me@ptmr]/home/me$ perl -le 'print (-2) ** 4 ' # this puzzled me -2 [me@ptmr]/home/me$ perl -le 'print ((-2) ** 4)' # parenthesis force wh +at I want 16

but I guess print is handling the second case as a list followed by some irrelevance, do I have that about right ?

Update: Thanks Fletch now I have been enlightened! I last read perlfunc a long time ago and had not really absorbed it all at the time. Now I see the explanation print (something) something_else gives the warning print (...) interpreted as function because it looks like a function.


Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^3: ** operator in perl
by Fletch (Chancellor) on Feb 03, 2009 at 13:16 UTC

    print is a list operator, so the second parses as (print(-2))**4 and will produce a warning if you run with -w/warnings (Useless use of exponentiation (**) in void context at -e line 1.).

    Update: I mean it's not like perlfunc uses print as the example of precedence issues that can come up with list operators right in the second paragraph or anything . . .

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://740976]
[holli]: I got into a fight yesterday and won.
[holli]: No, that's not true. I started it.
[holli]: I was company to my mother, bringing her to the therapy she has to take. There was another so called therapist outside smoking. We engaged in a talk with her and he turned out to be one of these lunatics telling people when they are sick it's their own
[holli]: fault for not thinking positively enough.
[LanX]: did he seriously hurt his fist at your nose in the end?
LanX .oO(positively thought)

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2017-12-13 17:57 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (373 votes). Check out past polls.