You combine several methods of processing modules and objects - and end up not working.
Here are four approaches that work:
1 / My :: Module is a library. trim is not exported.
$ cat My/Module.pm package My::Module; use strict; use warnings; sub trim { my $str = shift; $str =~ s{ \A \s+ }{}xms;
2 / My :: Module is a library. trim is exported.
$ cat My/Module.pm package My::Module; use strict; use warnings; use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(trim); sub trim { my $str = shift; $str =~ s{ \A \s+ }{}xms;
3 / MyModule is a class. trim is a class method.
$ cat My/Module.pm package My::Module; use strict; use warnings; sub trim {
4 / MyModule is a class, trim is an object method.
$ cat My/Module.pm package My::Module; use strict; use warnings;
I think you were trying to choose option 1. In this case, I would recommend option 2.
And answer your last question. You get this error because you are trying to call a method on a variable ($ My :: Module), which is undefined.
Dave cross
source share