in reply to Re: Using a subroutine as a module
in thread Using a subroutine as a module
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Using a subroutine as a module
by ysth (Canon) on Nov 03, 2003 at 06:25 UTC | |
|
Re: Re: Re: Using a subroutine as a module
by Anonymous Monk on Nov 03, 2003 at 10:12 UTC | |
by bobn (Chaplain) on Nov 03, 2003 at 15:43 UTC |