Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Pre vs Post Incrementing variables

by girarde (Friar)
on Sep 14, 2010 at 12:44 UTC ( #860102=note: print w/ replies, xml ) Need Help??


in reply to Pre vs Post Incrementing variables

My guess: the entire right hand expression is evaluated before assignments are made. Reasonable except when you want something else, but in that case, what should the rule be instead?


Comment on Re: Pre vs Post Incrementing variables
Re^2: Pre vs Post Incrementing variables
by JavaFan (Canon) on Sep 14, 2010 at 15:58 UTC
    My guess: the entire right hand expression is evaluated before assignments are made.
    Good guess. Doesn't really answer the question though, as any assignment will evaluate the RHS before doing the assignment. (If it didn't, what would it assign? Purple monkeys?)

      Pink. Purple is on Thursdays.

      --MidLifeXis

        Except at night.

      Actually, it does. Evaluating that right hand increments $i twice. This occurs before either of the assignments.
Re^2: Pre vs Post Incrementing variables
by ikegami (Pope) on Sep 14, 2010 at 19:26 UTC

    My guess: the entire right hand expression is evaluated before assignments are made.

    Of course it does, but it doesn't explain anything. The question can be phrased as "Why is the output of the first snippet different from the output of the following snippets in the following code?"

    $ perl -E'$i=0; ($j, $k) = (++$i, ++$i); say "j:$j k:$k";' j:2 k:2 $ perl -E'$i=1; ($j, $k) = ($i++, $i++); say "j:$j k:$k";' j:1 k:2 $ perl -E'$i=0; ($j, $k) = (++$i+0, ++$i+0); say "j:$j k:$k";' j:1 k:2

    The answer is here.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-12-25 08:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls