Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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 exploiting the Monastery: (7)
As of 2014-12-26 03:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (164 votes), past polls