Daniel Kasak <[EMAIL PROTECTED]> wrote:

: I have a main script file, a package in a separate 'package_name.pm'
: file and a file 'stuff.pl' that contains functions that both the
: main script and the package need to use.
: 
: I've tried adding:
: 
: require "stuff.pl";
: 
: to both the main script and the package. I can then call functions
: in 'stuff.pl' from the main script, but when I try from the package,
: I get:
: 
: ***   Undefined subroutine &package_name::function_name called at
: package_name.pm line 545. 
: 
: So Perl is only looking inside the package for functions, it
: that right?

    Probably. It's hard to tell without the code.


: How do I tell it to look outside the package for functions?

    IMO, the easiest thing to do in the log run is to change
"stuff.pl" into a module called (perhaps) "stuff.pm". The you
can "use" it. You might end up with something like this:

package stuff;

require Exporter;
@ISA = qw(Exporter);

@EXPORT_OK = qw( foo );

sub foo {
    return 'foo';
}

1;

    It would be called like this:

#!/usr/bin/perl

use strict;
use warnings;

use lib '.';
use stuff 'foo';

print foo();

__END__


    Read the docs for Exporter on how to export functions and
variables easily. Read perlmod for more info on writing modules.

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to