Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Help me to understand increment / decrement operator behavior in perl

by vinoth.ree (Monsignor)
on Mar 04, 2015 at 06:07 UTC ( [id://1118714]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use strict;
    use warnings;
    ...
    
    #Output
    # T2
    
  2. or download this
    my $foo = 1;
     
    # post decrement (printed and then decremented to 0)
    print $foo--; # prints 1
    print $foo;   # prints 0
    
  3. or download this
    my $foo = 1;
     
    # pre-decrement (decremented to 0 then printed)
    print --$foo;  # prints 0
    print $foo;    # prints 0
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-03-28 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found