in reply to Using a subroutine as a module
You start it with a shebang line, which is an odd thing to do since it is not actually executed (nor will any flags such as -w be parsed from the line by perl).
Usually (but only optionally) a module will declare its own name space and only export to the use'ing code subs that are requested:
in MyModule.pm:
and in the calling code:package MyModule; use Exporter (); our @ISA = 'Exporter'; our @EXPORT_OK = qw/foo bar/; sub foo { "do some foo stuff" } sub bar { "do some bar stuff" } 1; # not actually needed since @EXPORT_OK= evaluates as true
You might take a look at perlmod.pod for more info on creating modules.use MyModule 'foo'; &foo();
One last comment: one-level all-lowercase names like "validate" are usually for pragmas and are reserved for use by perl5-porters.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Using a subroutine as a module
by bobn (Chaplain) on Nov 03, 2003 at 02:09 UTC | |
by ysth (Canon) on Nov 03, 2003 at 06:25 UTC | |
by Anonymous Monk on Nov 03, 2003 at 10:12 UTC | |
by bobn (Chaplain) on Nov 03, 2003 at 15:43 UTC |