FreeKB - Perl Addition and Increment (+)
Perl - Addition and Increment (+)

Here is a basic example of how to add two numbers.

my $sum = (1 + 1);
print "$sum \n";

 

Which should return the following.

2

 


Increment

++ can be used to increment a value by one.

my $value = 1;
++$value;
print "$value \n";

 

Which should return the following.

2

 


Appending

+= can be used to add to an already set value.

$i = 1;
$i += 2;

print "$i \n";

 

Which should return the following.

3

 


Decimal numbers

By default, decimal will be used.

my $sum = (1.1 + 1.1);
print "$sum \n";

 

Which should return the following.

2.2

 


Whole numbers

The integer module can be used to round to whole numbers.

use integer;
my $sum = (1.1 + 1.1);
print "$sum \n";

 

Which should return the following.

2


Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 1a3c6 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |