Morse, Loretta ([EMAIL PROTECTED]) wrote:
>
> Hello,
>
> Does anybody know how to call a subroutine that is in a .pm file from
> another .pm file.
That depends:
First you have to load the file via 'require' or 'use' - perldoc them.
If your other .pm creates its own namespace, you need to address it
as &Module1::test
If the .pm has no private namespace, you can use the function just by
its name. Here's some sample code:
---------- check.pl ----------
#!/usr/bin/perl -w
use strict;
use Module1;
use Module2;
&test1;
#BROKEN: &test2;
&Module2::test2;
---------- check.pl ----------
---------- Module1.pm ----------
sub test1 { print "Module1.pm\n"; }
1;
---------- Module1.pm ----------
---------- Module2.pm ----------
package Module2;
sub test2 { print "Module2.pm\n"; }
1;
---------- Module2.pm ----------
Try de-commenting out the '#BROKEN: ' line and see what happens.
Of course, things will become more complicated once you learn about the
Exporter module - perldoc Exporter
--
If we fail, we will lose the war.
Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED]
Nordstr. 49 | http://www.lamertz.net
50733 Cologne | Work: +49 221 3091-121
Germany | Priv: +49 221 445420 / +49 171 6900 310