use calls require , which looks for a file with the package name (c / for :: and + .pm ).
So require actual package file, then import from the packages.
main.pl
use warnings; use strict; require MyModule; import Multipackage1; import Multipackage2; import Multipackage3 qw(test3); print "Calling first package:\n"; test1(); print "Calling second package:\n"; test2(); print "Calling third package:\n"; test3();
In MyModule.pm put each package in its own block to provide scope for lexical variables, since package does not. Since v5.14 (I think), you can do this with package Pack { ... } . For all of these 1 s there is no need, and you can pull out use Exporter; from blocks.
Exit
Calling first package:
First package
Calling second package:
Second package
Calling third package:
Third package
Better yet, replace our @ISA = qw(Exporter); on use Exporter qw(import); for
use strict; use warnings; package Multipackage1 { use Exporter qw(import); our @EXPORT = qw(test1); sub test1 { print "First package\n" } } ... 1;
with the same exit.
Please note that placing multiple packages in one file is usually not required and is not performed.
zdim
source share