"enable" -value function for Perl

I have a function that I would like to define in two different Perl scripts, but don't like to edit them. Is there any way that I can have includeit (as in PHP) from an external file?

FUNC FILE:

sub test {

}

FILE 1:

include func_file;
foo();
bar();
test();

FILE 2:

include func_file;
blah();
test();
+5
source share
2 answers

Func.pm:

package Func;

use Exporter qw( import );
our @EXPORT = qw( test );

sub test {
}

1;

File1.pl:

use Func;

test();
+6
source

To answer the question narrowly:

Yes, you can include the file using the require ('filename') function .

To answer the question as a whole:

Perl . perlmod. , CPAN .

+9

All Articles