Hi,

I have tried your code with two different variables as below, Is works as expected.

use strict; use warnings; my $a = 10; my $b = 10; #IMHO: $a-- should finish the current operation and then -1 if ($a == $b--) { print "\n T1"; } $b=10; #IMHO: --$a should -1 first and continute with current operation , i.e + if compare if ($a == --$b) { print "\n T2"; } #ENV: #Active Perl 5.20, Windows 7, x64 #Output # T2

Unary

The auto-decrement (--), and auto-increment (++) operators are unary operators. They alter the scalar variable they operate on by one logical unit. On numbers, they add or subtract one.Operators that come in post- and pre- varieties can be used two ways. The first way returns the value of the variable before it was altered, and the second way returns the value of the variable after it was altered.

my $foo = 1; # post decrement (printed and then decremented to 0) print $foo--; # prints 1 print $foo; # prints 0
my $foo = 1; # pre-decrement (decremented to 0 then printed) print --$foo; # prints 0 print $foo; # prints 0


All is well. I learn by answering your questions...

In reply to Re: Help me to understand increment / decrement operator behavior in perl by vinoth.ree
in thread Help me to understand increment / decrement operator behavior in perl by sam_bakki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.