Bootstrap FreeKB - Perl (Scripting) - Subtraction (-)
Perl (Scripting) - Subtraction (-)

Updated:   |  Perl (Scripting) articles

Here is a basic example of how to subtract two numbers (integers) in Perl.

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

 

Which should return the following.

1

 


Decrement

-- can be used to decrement a value by one.

my $value = 10;
--$value;
print "$value \n";

 

Which should return the following.

9

 


Decimal numbers

By default, decimal will be used.

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

 

Which should return the following.

1.7

 


Whole numbers

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

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

 

Which should return the following.

1

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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