What exactly is a .pm file?

A .pm file is just another Perl source file right? That is interpreted by Perl just like any other Perl code file that I create. Right?

Yes, this is true. However, some modules have additional parts in C or XS, which are loaded into perl using something called the DynaLoader.

Also, there is a Perl package called Inline, which allows you to include, in amongst your perl code, C and C++ code [and some other languages, too... I think python and ruby? not sure on those], which will mostly be compiled the first time the module is used.

Since the above is the case (in my understanding) why do I read of having to compile a module before installing it?? I have created modules and just 'use lib'ed them in my Perl code. Without any compilation at all.

The difference is that the modules you've created are 'pure perl' while many modules are not. The reason why code is written in C/C++/XS and compiled and linked into perl, is that it results in much faster execution than pure perl.

Perl depends on calls to your system's C libraries. Since different types of machines have different C libraries the 'compilation' is more like 'configuration'. In WinSpeak that routine outlined above is what the Setup.exe program does for many pieces of Win32 software.

At least on Windows. Now I know that references to compilation are mainly geared toward UNIX but I am wondering as to the relationship between Perl, the .pm sourc file, and the compilation need??

It's generally not the .pm file which gets compiled, but things which come with it. As I said, many bundles come with .xs files, or perl code which creates .xs files, which get transformed into dynamiclly linked libaries by the makefile [which calles the appropriate compiler].

The reason I am asking is that apparently I cannot just copy the .pm I install and use under Windows Perl to my UNIX hoster. Or can I??

If a module is pure perl, you can. If the module comes with a .dll on windows, you cannot [unless you own a magic wand which can turn windows dynamically linked libraries (.dll) into unix shared objects (.so)].

There seems to be some kind of compiled file that gets installed on my Windows system along with the .pm file.

You get a compiled thing for each module which has external code beyond the Perl code.

Can I just take a .pm file, copy it to my UNIX hoster, and then using Telnet, compile the file with their version of the C compiler?? Can someone clarify this for me?

If it needs to be compiled, you would copy the .pm files, the .xs files, the makefile.pl, and all other things *except* the .dlls, then run the makefile. If it doesn't need to be compiled, just copy the .pm file.

Some do, some don't. If it says that it uses DynaLoader, then it's got compiled parts which you don't see in the .pm file.

Modules are delivered in bundles, you extract them to a working directory, and you typically run

which shoves the modules (and any .xs files which have been compiled) into the proper library location. This is colloquially called compiling the
module, even though true compilation doesn't necessarily have to occur. It's just convention.


Published Thursday, July 15, 2004