LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 01-27-2002, 04:39 PM   #1
gene_gEnie
Member
 
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
example?

Thanks in advance

Martin
 
Old 01-30-2002, 09:47 AM   #2
joe1011010
Member
 
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() {
...;
}
1;

Make sure you include the last line. Save it as file1.pm

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

use file1;

&file1::routine1();
&file1::routine2();

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.

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

Rep: Reputation: 15
Create your own modules.

http://www.perldoc.com/perl5.6.1/pod/perlmod.html

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
gene_gEnie
Member
 
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.

Martin
 
  


Reply


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


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

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