Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: question 1st - undefined behaviour (perlop)

by rumos2 (Acolyte)
on Sep 23, 2013 at 23:30 UTC ( [id://1055405]=note: print w/replies, xml ) Need Help??


in reply to Re: question 1st - undefined behaviour (perlop)
in thread question 1st - undefined behaviour

I've mean exactly this -
my $x=5;
my $y=$x + ++$x;
$y returns 12.

here $x in first position is used as original $x and it's returns it's changed value after calculation of pre-increment.

my $x=5;
my $y=$x + ++$x + $x++
$y returns 18. precedence crash(5($x) + 7(++$x is 6, but returns $x and become 7 after next step) + 6($x++, at now $x is 7, but here we get copy before increment and get 6) in this order) or $x is used as a copy at here (like after $x++) and this copy is maked BEFORE any changes.
my $x=5;
my $y=++$x + $x++ + $x
$y returns 20 -
++$x return $x and make it's value 6; $x++ return 6 forever, but $x is 7 at now
7 + 6 + 7 == 20 - ok.
  • Comment on Re^2: question 1st - undefined behaviour (perlop)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-19 08:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found