Perl 包问题

发布于 2024-09-09 01:45:06 字数 395 浏览 7 评论 0原文

我是 Perl 新手。

我下载了一个 Perl 应用程序,它的源文件中有这样一行:

 use PWING::Utils::Utils;

它导入了一个看起来像这样的文件。

我下载了一个 Eclipse 插件 [Perl-Eclipse 集成]。 当我尝试将该文件作为 Perl 应用程序启动时,它说找不到导入的资源。

现在的问题是,perl 包结构是什么样的?

该行意味着必须有这样的目录结构:

    PWING - 
          Utils - 
                 Utils.pm ?

我看到我下载的应用程序不包含这样的结构,那么如何并且应该启动?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扬花落满肩 2024-09-16 01:45:06

perlmod 文档指出

所有 Perl 模块文件的扩展名为 .pmuse 运算符假定了这一点,因此您不必在引号中拼写出 "Module.pm"。这也有助于区分新模块与旧的 .pl.ph 文件。模块名称也大写,除非它们用作编译指示;编译指示实际上是编译器指令,有时称为“实用模块”(如果您是古典主义者,甚至称为“pragmata”)。

两条语句:

需要一些模块;
需要“SomeModule.pm”;

彼此之间有两个不同之处。在第一种情况下,模块名称中的任何双冒号(例如 Some::Module)都会被转换为系统的目录分隔符,通常为“/”。

...

Perl 包可以嵌套在其他包名称中,因此我们可以使用包含 :: 的包名称。但是,如果我们直接使用该包名称作为文件名,则会在某些系统上产生难以使用或不可能的文件名。因此,如果模块的名称是 Text::Soundex,那么它的定义实际上可以在库文件 Text/Soundex.pm 中找到。

特殊的 @INC 数组包含要搜索的目录对于模块:

@INC

数组@INC包含do EXPRrequireuse构造的位置列表查找他们的库文件。它最初由任何 -I 命令行开关的参数组成,后跟默认的 Perl 库,可能是 /usr/local/lib/perl,最后是 >".",代表当前目录。 (如果通过 -T-t 启用了污点检查,则不会附加 "."。)如果您需要修改在运行时,您应该使用 use lib pragma 来正确加载依赖于机器的库:

使用 lib '/mypath/libdir/';
使用一些模组;

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;
和影子一齐双人舞 2024-09-16 01:45:06

在 Unix 系统上,该文件可以在以下形式的目录中找到,

 lib/PWING/Utils/Utils.pm

但问题是检测顶级目录“lib”可能在哪里。

如果该模块安装在您的系统上,它将被放置在 Perl 可以找到的地方。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文