The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Install Perl Module hari.jnvc90 SUN Solaris 1 03-05-2008 06:08 AM
Can I use a Perl Module without installing it? jjinno Shell Programming and Scripting 1 08-29-2007 10:55 AM
help with perl module installation sabyasm UNIX for Advanced & Expert Users 2 01-04-2007 05:13 AM
PERL DBI module install jerardfjay Shell Programming and Scripting 3 10-27-2006 07:29 AM
Replace Perl Module name in all Perl scripts rahulrathod Shell Programming and Scripting 2 12-01-2005 09:00 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-06-2003
Registered User
 

Join Date: Feb 2002
Location: PARIS (FRANCE)
Posts: 22
Stumble this Post!
Writing perl module

Hi,

I'd like to create perl functions in separate file from my scripts.
Does somebody know if it's possible to create and use a perl module without compiling it ?

Thanks.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-06-2003
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,432
Stumble this Post!
Yes. Perl modules have the extension ".pm" instead of the regular ".pl". Each Perl module is a class, in object-oriented programming (OOP) terms.

However, writing Perl modules require higher levels of Perl knowledge. In particular, you need to be proficient with references. Then, you can find more about writing Perl modules in the perlobj and perltoot manpage. But I guess these manpages are generally not easy to read. You should find a guidebook somewhere that talks about that. I can't tell you much about this here because this is not something I can explain with just a few lines of code and description.

But if you just want to keep your functions in a separate file without adopting an OOP style, the way I showed you in your previous thread (that is, use require() to source in an external file) is already sufficient. Best of all, that's easiest unless you need to adopt a pure object-oriented approach.
Reply With Quote
  #3 (permalink)  
Old 08-06-2003
Registered User
 

Join Date: Feb 2002
Location: PARIS (FRANCE)
Posts: 22
Stumble this Post!
I just need to create few basic functions in separate files like this one:
# lib.pl
sub fonc
{
$arg1=$_[0];
$arg2=$_[1];
print "arg1=$arg1, arg2=$arg2\n";
}
1;

I try to call this module in my main script but it seems not so easy :
# main.pl
use "lib.pl";
&fonc('test','ok');
Reply With Quote
  #4 (permalink)  
Old 08-06-2003
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,432
Stumble this Post!
You should use require "lib.pl" instead here, because use() is for Perl modules only.
Reply With Quote
  #5 (permalink)  
Old 08-06-2003
Registered User
 

Join Date: Feb 2002
Location: PARIS (FRANCE)
Posts: 22
Stumble this Post!
sorry ... and THANKS.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0