CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How to include 1 script in other script

 



naven8
Novice

Apr 9, 2012, 4:52 AM

Post #1 of 2 (638 views)
How to include 1 script in other script Can't Post

I have two scripts "a.pl" and "b.pl". I have written some common functionality in a.pl so that i can use it in other scripts.
Can someone give some idea on how to include this to other scripts?

I can think of 3 ways to do it :
1) do a.pl
2) use "a.pl"
3) require "a.pl"

I am not sure which one is best. Is there any other way to do it?


BillKSmith
Veteran

Apr 9, 2012, 8:40 AM

Post #2 of 2 (625 views)
Re: [naven8] How to include 1 script in other script [In reply to] Can't Post

The best answer is "none of the above". Without an extremely good reason to do otherwise, your common functions should be put in a module. The module should be included with the command like:


Code
use Mylib::a.pm qw( func1 funct2 );



Refer to the "Perl Modules" section of perldoc perlmod for a template for creating a module.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives