LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Perl Module and Calling Functions of Another Perl Source File (http://www.linuxquestions.org/questions/programming-9/perl-module-and-calling-functions-of-another-perl-source-file-858853/)

devUnix 01-26-2011 03:13 PM

Perl Module and Calling Functions of Another Perl Source File
 
When do we name a Perl source/code file .pm and .pl?

Examples:

Sample.pm
Sample.pl

And also how do we include a Perl source/code file into another one?

Example:

first.pl calls the functions written in second.pl

Any help?

Note: I just found we can use the use directive, and that .pm is for using functionality of a Perl Module within in a Perl source/code file.

I am leaving this threas as open just for the gurus out here to throw more light upon the subject; or whatever they would like to add to it from their experience.

j-ray 01-27-2011 04:22 AM

A perl module is a more or less complex project that may consist of several files with a central .pm. Her's a howto: http://mathforum.org/~ken/perl_modules.html
If I don't mix it, you can use

require '2ndfile.pl';

...if you want to include some functions from 2ndfile.pl

Sergei Steshenko 01-28-2011 04:58 AM

Quote:

Originally Posted by devUnix (Post 4238599)
...they would like to add to it from their experience.

Read the documentation. I.e. start from http://perldoc.perl.org/ .

At all, RTFM:

Code:

man perl
- among other things you'll see:

Code:

          perlmod            Perl modules: how they work
          perlmodlib          Perl modules: how to write and use
          perlmodstyle        Perl modules: how to write modules with style
          perlmodinstall      Perl modules: how to install from CPAN
          perlnewmod          Perl modules: preparing a new module for distribution

.

devUnix 01-28-2011 02:42 PM

Thanks!

Please, change your signature line "If Python don't have..." to "If Python doesn't have..."

Sergei Steshenko 01-28-2011 04:53 PM

Quote:

Originally Posted by devUnix (Post 4240868)
Thanks!

Please, change your signature line "If Python don't have..." to "If Python doesn't have..."

My signature is a literal quote; since it's a quote, I can't change it.


All times are GMT -5. The time now is 11:15 PM.