Perl (Scripting) - Division (/)

by
Jeremy Canfield |
Updated: August 04 2022
| Perl (Scripting) articles
Here is the most basic example of how to divide two numbers in Perl.
#!/usr/bin/perl
use strict;
use warnings;
print (10 / 2);
It is much more common to store the result in a variable.
#!/usr/bin/perl
use strict;
use warnings;
my $result = (10 / 2);
print "result = $result \n";
Which should return the following.
5
Decimal numbers
By default, decimal will be used.
#!/usr/bin/perl
use strict;
use warnings;
my $result = (10.2 / 2.5);
print "result = $result \n";
Which should return the following.
4.08
Whole numbers
The integer module can be used to round to whole numbers.
#!/usr/bin/perl
use strict;
use warnings;
use integer;
my $result = (10.2 / 2.5);
print "result = $result \n";
Which should return the following.
5
Did you find this article helpful?
If so, consider buying me a coffee over at