Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Re: Mysterious for behavior

by Belgarion (Chaplain)
on Apr 22, 2004 at 22:05 UTC ( #347488=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Mysterious for behavior
in thread Mysterious for behavior

Post-increment does not yield a new lvalue, but it does have an lvalue, and does modify the variable. Update: I don't what I was thinking about there. Post-increment has an rvalue. (That's what happens when you try to post a message just before quitting time!) However, below is still semi-interesting. Consider:

print "$_ and $i\n" for ($i = 1, $i++, $i++); __OUTPUT__ 3 and 3 1 and 3 2 and 3

The $i is being modified, and the value before the post-increment is used in the list. Playing around, you could do something like:

print "$_ and $i\n" for (\($i = 1, $i++, $i++)); print \$i , "\n"; __OUTPUT__ SCALAR(0x8176c44) and 3 SCALAR(0x815dcc0) and 3 SCALAR(0x815dad4) and 3 SCALAR(0x8176c44)
This shows that the first element of the list is the $i variable, and that perl generates two temporary scalars to hold the values of $i prior to increment. Also, the entire list is evaluated before iteration.

Interesting stuff you found here!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2018-09-20 09:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (174 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!