tags:

views:

89

answers:

2

I am facing a problem that require the reuse some of the functions within another Perl script. I am writing some test scripts. The test scripts are basically build on each other.

Say Script 1 does:

Some code to prepare the test. A. B. C. Some code to determine the success.

Then Script 2 does:

Some code to prepare the test. A. B. C. D. E. Some code to determine the success.

How can I reuse A.B.C of script 1 in script 2?

Calling script 1 from script 2 will not work because of the the code to determine the success of the script. What is the best way to do this?

Thanks

+10  A: 

Put the functions in a module and include that from both files.

See http://perldoc.perl.org/perlmod.html for more info.

Corey
Thanks for the reply.
+5  A: 

Foo/Common.pm:

package Foo::Common;
use strict;
use warnings;
use parent 'Exporter';
our @EXPORT_OKAY = qw(frob borf);

sub frob {}
sub borf {}

1;

In some script or module, give or take a use lib to get Foo/Common.pm in @INC:

use Foo::Common qw(frob borf);
frob();
Anonymous
Can you provide a link to its documentation? Thanks.
@user: Which, Exporter? Try `perldoc Exporter` at the command line or terminal.
Anonymous
@user1923452345234234564563657758, perldoc.perl.org has the entire FM for your reading pleasure. http://perldoc.perl.org
daotoad
@daotoad I think you mean user8675309.
hobbs