### Quantum Weirdness and the Increment Operator

by barrachois (Pilgrim)
 on Jun 24, 2004 at 05:34 UTC Need Help??

```  \$m = 20;  print ++\$m + \$m++;
```
```  \$m = 20;  print noop(++\$m) + \$m++;

sub noop{ return shift }
```
```   # This is an attempt at emulating ++\$m with preInc(\$m)
sub preInc {
...
my \$m = 20;
print preInc(\$m) + \$postInc(\$m);   # This prints 42.
# The final value is \$m is 22.
```
```   my \$m=20;
print ++\$m + \$m++;           # This prints 43 !
# The final value is \$m is still 22.
```
```   # Print values and addresses of passed argument and \$m.
sub look {
...
my \$m = 20;
my \$p = look(++\$m) + look(\$m++);
print \$p;
```
```   sub noop {        # do nothing
return shift;
}

my \$m=20; print noop(++\$m) + \$m++;     # This prints 42 !
```
```   ==== increment weirdness: ++\$m + \$m++ ==========
m = 20 at 0x80ab23c
...
*** add : 22 at 0x804c120 + 21 at 0x80ab23c = 43 at 0x80ab11c
m is 22 at 0x804c120
p = 43 at 0x80ab11c
```

Create A New User
Node Status?
node history
Node Type: perlmeditation [id://369247]
Approved by BrowserUk
Front-paged by broquaint
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2017-06-28 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many monitors do you use while coding?

Results (638 votes). Check out past polls.