you might consider using the Package pragma:
(File1.pm)
use strict;
Package File1;
sub foo {
print("Foo!\n");
}
(end File1.pm)
(File2.pm)
use strict;
Package File2;
use File1;
sub foo {
print "File1::foo() -> ";
File1::foo();
}
(end File2.pm)
(file main.pl)
#!/usr/bin/perl -w
use strict;
use File1;
use File2;
sub foo {
print "baz\n";
}
File1::foo();
File2::foo();
foo();
(end main.pl)
Note that the package name was used to specify which function called
foo() we were referring to, as there are three, all doing different things.
Hope this helps,
C.J.
> Thanks for the suggestions however I think I need to clarify
> what I'm trying to do.
>
> I am using a WinNT system and I'm running a script that calls
> a subroutine in file1.pm. Then file1.pm calls a subroutine
> from file2.pm. The script can't seem to find the subroutine
> that in is in file2.pm.
>
> Neither suggestion has worked so far, any other ideas out there?
>
> Thanks.
>
> -----Original Message-----
> From: Michael Lamertz [mailto:[EMAIL PROTECTED]]
> Sent: Friday, April 27, 2001 4:06 PM
> To: Morse, Loretta
> Cc: '[EMAIL PROTECTED]'
> Subject: Re: subroutines in .pm
>
>
> 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
>