Access to perl routine from different perl script

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

# Try_1.pl main(); sub main{ --- --- check(); } check { -- --} 

Now I have written another script Try_2.pl in which I want to call the control routine perl script Try_1.pl .

+4
source share
4 answers

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

 package Try_1; use base 'Exporter'; our @EXPORT = qw(check); sub check { } 1; 

And then Try_2.pl should get this code:

 use Try_1 qw(check); 

What are you looking for?

+7
source

If you do not use modules (extension .pm ), but instead use libraries (extension .pl ):

 require 'Try_1.pl'; check(); 

Make sure both Try_1.pl and Try_2.pl are in the same directory.

+5
source

You may need

test1.pl:

 use Routines; { my $hello = "hello123"; hello( $hello ); # ... } 

test2.pl:

 package Routines; sub hello { my $hello = shift; print "$hello\n"; } 1; 
+1
source

"run" a response check, but you need to call "Try_1 :: check ()". Otherwise, show the error "Undefined routine & main :: check ()".

0
source

All Articles