in reply to Exporter Module
Your Module.pm doesn't set up a separate namespace from which functions may be imported by another package. All your functions are compiled into the caller's namespace:
Extending your Module.pm functions slightly
require Exporter; @ISA = qw(Exporter); @EXPORT =qw\fun1 fun2\; @EXPORT_OK = qw\fun3\; @EXPORT_FAIL= qw\fun4\; sub fun1{print "\nfun1 in package " . __PACKAGE__ } sub fun2{print "\nfun2 in package " . __PACKAGE__ } sub fun3{print "\nfun3 in package " . __PACKAGE__ } sub fun4{print "\nfun4 in package " . __PACKAGE__ }
the script
use Module; fun1; fun2; fun3; fun4;
outputs
fun1 in package main fun2 in package main fun3 in package main fun4 in package main
Nothing exported, nothing imported. All is in the default package 'main'.
Use a package statement in your Module.pm:
package Module; require Exporter; @ISA = qw(Exporter); ...
Running the script again yields
fun1 in package Module fun2 in package Module
|
|---|