Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing perl subroutine from different perl script

Tags:

perl

I had 1 perl script in which we write couple of subroutines. Example:

# Try_1.pl

main();

sub main{
---
---
 check();
}

check {
--
--}

Now, i wrote another script Try_2.pl, in which i want to call check subroutine of perl script Try_1.pl.

like image 800
RohitJain Avatar asked Dec 13 '22 12:12

RohitJain


1 Answers

It sounds like you want to create a module. Try_1.pm (Edit: note extension) should have the following form:

package Try_1;
use base 'Exporter';
our @EXPORT = qw(check);

sub check {
}

1;

And then Try_2.pl needs to get that code:

use Try_1 qw(check);

That what you're looking for?

like image 74
Tamzin Blake Avatar answered Jan 05 '23 00:01

Tamzin Blake