Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Nov 012010

Force Perl to use integer arithmetic


To force Perl to use integer arithmetic, instead of floating point, you just need to add the statement "use integer;" at the beginning of your script.


use strict;
use warnings;
use integer;

my $i = 10/3;
print $i; 

It above program will print out 3 instead of 3.333..

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>