I have a module called Helpers.pm :
use warnings; use 5.012; package Helpers; use Exporter qw(import); our @EXPORT_OK = qw(my_function); sub my_function { return { one => 1, two => 2 }; } 1;
call it in the script:
#!/usr/bin/env perl use warnings; use 5.012; use Data::Dumper; use FindBin qw($RealBin); use lib $RealBin; use Helpers qw(my_function); my $ref = my_function(); say Dumper $ref;
and I do not receive error messages. But when I put the module in the TestDir directory, change the script as follows:
#!/usr/bin/env perl use warnings; use 5.012; use Data::Dumper; use FindBin qw($RealBin); use lib $RealBin; use TestDir::Helpers qw(my_function); my $ref = my_function(); say Dumper $ref;
I get this error message:
Undefined subroutine &main::my_function called at ./perl.pl line 10.
Why am I getting this error message?
module perl
sid_com
source share