Few things:
First use Local as your module prefix. Thus, if you just have a module with the same name in your Perl installation, it will use yours. Name it "Local :: Module". Then create the Local directory and name your module Module.pm .
Another thing you need to understand is that you define your module in a different namespace. By default, everything is in the main namespace until you use the package statement. This creates another namespace that your package uses. That way, if your package has a foo function, and you defined the foo function in your main program, they will not collide.
Thus, you have two options: one (preferably now) is to simply call your routine with the full package name added to it. The second way is to export the subroutine names into your main program. This can cause problems with duplicate names, but you do not need to constantly enter a package name every time you call your routine.
No name export
Local / Module.pm
# /usr/bin/env perl # Local/Module.pm package Local::Module; use strict; use warnings; sub Parse { my $value = shift; #Might as well get it. print "I got a value of $value\n"; return $value; } 1; #Need this or the module won't load
program.pl
# /usr/bin/env perl # program.pl use strict; use warnings; use Local::Module; Local::Module::Parse("Foo");
When exporting:
Local / Module.pm
# /usr/bin/env perl # Local/Module.pm package Local::Module; use strict; use warnings; use Exporter qw(import); our @EXPORT_OK(Parse); #Allows you to export this name into your main program sub Parse { my $value = shift; #Might as well get it. print "I got a value of $value\n"; return $value; } 1; #Need this or the module won't load
program.pl
# /usr/bin/env perl # program.pl use strict; use warnings; use Local::Module qw(Parse); Parse("Foo");
source share