![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
|||
|
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. |
|
|||
|
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'); |