Curious Curious - 5 months ago 13
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


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