Auto Increment or Decrement in Perl

by Geethalakshmi 2010-09-17 14:01:16

Auto Increment or Decrement in Perl


The ++ or -- symbols are used to increment or decrement a variable by one. Depending on whether the ++ or -- comes before or after the variable determines when it is incremented.

$d = 17;
$e = ++$d; # $e and $d both equal 18

$d = 17;
$e = $d++; # $e = 17 and $d = 18

$x = 12;
--$x; # $x = 11
$y = $x-- # $y = 11, $x = 10

Tagged in:

730
like
0
dislike
0
mail
flag

You must LOGIN to add comments