Curious Curious - 2 years ago 195
Perl Question

perl floor function giving error undefined subroutine &main::floor

I'm new to perl and following piece of code is not working and getting the following error. I tried googling but coundn't get any solution.

$halfSize = floor($halfSize);

Undefined subroutine &main::floor called

Answer Source

floor is spelt int in perl:

my $num = 22.8;
my $floor = int($num);
say $floor;
# => 22

If you miss the actual name of the function, you can use the POSIX version;

use POSIX qw/floor/;

my $num = 22.6;
my $floor = floor($num);
say $floor;
# => 22
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download