views:

65

answers:

2

I'm new to Perl.

I dowloaded a perl application, that has such a line in a source file:

 use PWING::Utils::Utils;

It imports a file as it seems.

I downloaded a plugin for Eclipse [Perl-Eclipse integration]. When I try to start that file as a perl app, it says it cannot find an imported resource.

Now the question is, what a perl package structure look like?

That line means there must be a catalog structure like this:

    PWING - 
          Utils - 
                 Utils.pm ?

I see that the app I downloaded does not contain such a structure, so how can and should be started?

A: 

On a Unix system this file would be found in a directory of the form

 lib/PWING/Utils/Utils.pm

but the problem is detecting where the top level directory 'lib' might be.

If the module is installed on your system it will be put into a place where Perl can find it.

Kinopiko
+3  A: 

The perlmod documentation states

All Perl module files have the extension .pm. The use operator assumes this so you don't have to spell out "Module.pm" in quotes. This also helps to differentiate new modules from old .pl and .ph files. Module names are also capitalized unless they're functioning as pragmas; pragmas are in effect compiler directives, and are sometimes called "pragmatic modules" (or even "pragmata" if you're a classicist).

The two statements:

require SomeModule;
require "SomeModule.pm";

differ from each other in two ways. In the first case, any double colons in the module name, such as Some::Module, are translated into your system's directory separator, usually "/".

...

Perl packages may be nested inside other package names, so we can have package names containing ::. But if we used that package name directly as a filename it would make for unwieldy or impossible filenames on some systems. Therefore, if a module's name is, say, Text::Soundex, then its definition is actually found in the library file Text/Soundex.pm.

The special @INC array contains directories to be searched for modules:

@INC

The array @INC contains the list of places that the do EXPR, require, or use constructs look for their library files. It initially consists of the arguments to any -I command-line switches, followed by the default Perl library, probably /usr/local/lib/perl, followed by ".", to represent the current directory. ("." will not be appended if taint checks are enabled, either by -T or by -t.) If you need to modify this at runtime, you should use the use lib pragma to get the machine-dependent library properly loaded also:

use lib '/mypath/libdir/';
use SomeMod;
Greg Bacon