The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 10:08 AM
Can I use a Perl Module without installing it? jjinno Shell Programming and Scripting 1 08-29-2007 01:55 PM
help with perl module installation sabyasm UNIX for Advanced & Expert Users 2 01-04-2007 09:13 AM
PERL DBI module install jerardfjay Shell Programming and Scripting 3 10-27-2006 10:29 AM
Replace Perl Module name in all Perl scripts rahulrathod Shell Programming and Scripting 2 12-02-2005 01:00 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-06-2003
jo_aze jo_aze is offline
Registered User
  
 

Join Date: Feb 2002
Location: PARIS (FRANCE)
Posts: 22
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.
  #2 (permalink)  
Old 08-06-2003
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
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.
  #3 (permalink)  
Old 08-06-2003
jo_aze jo_aze is offline
Registered User
  
 

Join Date: Feb 2002
Location: PARIS (FRANCE)
Posts: 22
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');
  #4 (permalink)  
Old 08-06-2003
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
You should use require "lib.pl" instead here, because use() is for Perl modules only.
  #5 (permalink)  
Old 08-06-2003
jo_aze jo_aze is offline
Registered User
  
 

Join Date: Feb 2002
Location: PARIS (FRANCE)
Posts: 22
sorry ... and THANKS.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0