Actually, better not to export at all:
in MyModule.pm:
and in the calling code:package MyModule; sub new { bless {}, shift } sub foo { "do some foo stuff" } 1;
$o is an object. It can have data, but in this case, it is just a way to tell perl where to find the subroutine foo(). This means you could have several different modules, each with a routine named 'foo;, and by using the object each module returns (customarily) from the call to new(), you can tell them apart. Whereas if you have the misfortune to use 2 modules that both export foo into your namespace, who knows what happens?use MyModule; my $o = new MyModule; $o->foo();
--Bob Niederman, http://bob-n.com
All code given here is UNTESTED unless otherwise stated.
In reply to Re: Re: Using a subroutine as a module
by bobn
in thread Using a subroutine as a module
by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |