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

-- 
                     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

Reply via email to