How can I reuse some functions in a Perl script?

I ran into a problem requiring reusing some functions inside another Perl script. I am writing some test scripts. Testing scenarios are mostly built on top of each other.

Tell Script 1:

Some code for preparing the test. ABC Some code for determining success.

Then Script 2 does:

Some code for preparing the test. ABCDE Some code for determining success.

How can I reuse ABC from Script 1 to Script 2?

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

thanks

+4
source share
2 answers

Put the functions in the module and include this from both files.

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

+10
source

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 use lib to get Foo / Common.pm in @INC:

 use Foo::Common qw(frob borf); frob(); 
+5
source

Source: https://habr.com/ru/post/1300451/


All Articles