Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-27-2002, 04:39 PM   #1
Registered: Aug 2001
Location: London UK
Distribution: Redhat 7.2, soon to be LFS!
Posts: 42

Rep: Reputation: 15
Including methods from a perl script into another perl script

Hi, can anyone tell me if it is possible to import methods that i have
written in one perl file into another perl file?

Sort of like using methods in the perl mods etc.

My problem being i have one huge monolith of a file at the moment and i
want to break it down into more managebale pieces.

If this is possible. Could anyone show me the syntax or point me to an

Thanks in advance

Old 01-30-2002, 09:47 AM   #2
Registered: Aug 2001
Location: UK
Posts: 48

Rep: Reputation: 15
Just to point in the general direction... this is not too clear as I am not too sure, but I did write a small script that worked.

1) Create a file in which you have several subroutines,

sub routine1() {
sub routine2() {

Make sure you include the last line. Save it as

2) In your main program, call these subroutines with,

use file1;


Not sure if there are other things related to this, but my small script did work like this. There may be issues with declaring variables, but not sure.

Hope it starts you on the way to a solution.

Old 01-30-2002, 03:38 PM   #3
Registered: May 2001
Location: Louisville, Kentucky, USA
Distribution: RedHat ES
Posts: 120

Rep: Reputation: 15
Create your own modules.

or from your command line:

perldoc perlmod

If it is just simple and small, place your subroutines in a file, oh, perhaps called 'myfuncs.lib' and then use the 'require' statement.

Do It Right, though, and make your own modules to save some grief later on.
Old 01-31-2002, 06:03 AM   #4
Registered: Aug 2001
Location: London UK
Distribution: Redhat 7.2, soon to be LFS!
Posts: 42

Original Poster
Rep: Reputation: 15
thanks for the replies.

I've gone down the module root and it all seems to be working correctly. I've stuck the module in the home/perllib directory that i created and did a
use lib "home/gjake/perllib";
to get at the mod.

Now i gonna all out and make it OOP! :-)

Thanks again.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl Script Help Rv5 Programming 5 10-03-2004 11:04 AM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 11:22 AM
Help with Perl Script dannyp Programming 0 07-18-2004 08:36 PM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 07:25 PM
Perl Script Gerardoj Programming 3 10-10-2003 12:18 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:35 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration