in reply to subroutine inheritance

First off, DynaLoader is not mandatory for what you want to do. Someone will probably explain you its use, because I personally don't know much about it. I know however that Exporter should be enough.

Second, you have a syntax error that would have been reported, had you turned on warnings.

@ISA = qw(Exporter, DynaLoader);

should be

@ISA = qw(Exporter DynaLoader); # no comma

Last, it's not necessary to specify which subroutine to import when using @EXPORT. It's only mandatory when going with @EXPORT_OK

Putting it all together, something like that will do what you want:

package MyModule; use strict; use warnings; # might want to turn this off once everything works fine use Exporter; our (@ISA, @EXPORT); @ISA = qw(Exporter); @EXPORT = qw(suba); sub suba { print "suba\n"; } 1;

Then, in your code:

#!/usr/bin/perl use strict; use warnings; use MyModule; suba();

Update: I had forgotten the necessary use Exporter; line... shame on me. Anyway, you'll want to read perldoc Exporter.

Replies are listed 'Best First'.
Re^2: subroutine inheritance
by chromatic (Archbishop) on Apr 20, 2005 at 16:42 UTC

    DynaLoader loads and initializes shared libraries, usually compiled XS code. It's fairly clever and unfortunately underused. Unless you write or use shared libraries directly, you don't need to know about it.

Re^2: subroutine inheritance
by ihb (Deacon) on Apr 20, 2005 at 20:23 UTC

    I had forgotten the necessary use Exporter; line... shame on me.

    Use use base 'Exporter'; instead and forget all about this @ISA and require/use Exporter; nonsense. ;-)

    ihb

    See perltoc if you don't know which perldoc to read!