DavidSzczesniak
12/14/2017 - 1:09 PM

Auto-increment operator (special behaviour)

The auto increment operator has special behaviour. Numeric compontents are incremented as you'd expect. However, if the value is a string, the operator increments the value's string component. So, a becomes b, zz becomes aaa, and a9 becomes b0.

my $num = 1;
my $str = 'a';

$num++;
$str++;
is $num,  2, 'numeric autoincrement';
is $str, 'b', 'string autoincrement';

no warnings 'numeric';
$num += $str;
$str++;

is $num, 2, 'numeric addition with $str';
is $str, 1, '...gives $str a numeric part';