Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl module error regarding "undefined subroutine"

I am trying to use a module called Math::Counting:

#!/usr/bin/perl 

use strict;
use warnings;
use Math::Counting;

my $f = factorial(3);
print "$f\n";

When I run it however, I get the following error

$ perl UsingModules.pl
Undefined subroutine &main::factorial called at UsingModules.pl line 8.

It seems like the function factorial is not being exported, but why?

When I used the following

my $f = Math::Counting::factorial(3);

instead of what was above, it works perfectly fine, but I am curious why the function cannot be exported.

I am using perl v5.10.1 on Cygwin.

like image 928
Alby Avatar asked Apr 25 '12 14:04

Alby


1 Answers

There is a bug in the module. Math::Counting ISA Exporter, but Math::Counting does not load Exporter.

Workaround: You can require or use Exporter manually.

Better: File a bug with the module author, provide a test case.

Comment:

Oh, very interesting. The module author does test his functions, but Test::More pulls in Exporter, meaning that this omission from the module source was not noticed.

Update:

Math::Counting 0.0904 has been released, addressing this issue.

like image 75
pilcrow Avatar answered Oct 16 '22 15:10

pilcrow