Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Quantum Weirdness and the Increment Operator

by barrachois (Pilgrim)
on Jun 24, 2004 at 05:34 UTC ( #369247=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
      $m = 20;  print ++$m + $m++;
    
  2. or download this
      $m = 20;  print noop(++$m) + $m++;
    
      sub noop{ return shift }
    
  3. or download this
       # 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.
    
  4. or download this
       my $m=20; 
       print ++$m + $m++;           # This prints 43 !
                                    # The final value is $m is still 22.
    
  5. or download this
       # Print values and addresses of passed argument and $m.
       sub look {
    ...
       my $m = 20;
       my $p = look(++$m) + look($m++);
       print $p;
    
  6. or download this
       sub noop {        # do nothing
        return shift;
       }
      
       my $m=20; print noop(++$m) + $m++;     # This prints 42 !
    
  7. or download this
       ==== 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 
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://369247]
Approved by BrowserUk
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-09-19 07:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (133 votes), past polls