相关疑难解决方法(0)

如何使用现代perl和utf8默认设置"使用My :: defaults"?

我想为我自己的"默认使用"制作一个模块,例如:

use My::perldefs;
Run Code Online (Sandbox Code Playgroud)

具有以下内容(主要基于tchrist的帖子.)

use 5.014;
use strict;
use features qw(switch say state);

no warnings;
use warnings qw(FATAL closed threads internal debugging pack substr malloc
                unopened portable prototype inplace io pipe unpack regexp
                deprecated exiting glob digit printf utf8 layer
                reserved parenthesis taint closure semicolon);
no warnings qw(exec newline);

use utf8;
use open qw(:std :utf8);
use charnames qw(:full);
use feature qw(unicode_strings);
use Encode qw(encode decode);
use Unicode::Normalize qw(NFD NFC);
use Carp qw(carp croak confess cluck);
use autodie; …
Run Code Online (Sandbox Code Playgroud)

perl cpan utf-8

15
推荐指数
1
解决办法
852
查看次数

有没有办法"使用"单个文件,而这个文件又在Perl中使用多个其他文件?

我想创建几个模块,这些模块将用于我项目中的几乎所有脚本和模块.这些可以在我的每个脚本中使用 d,如下所示:

#!/usr/bin/perl

use Foo::Bar;
use Foo::Baz;
use Foo::Qux;
use Foo::Quux;

# Potentially many more.
Run Code Online (Sandbox Code Playgroud)

是否可以将所有这些use语句移动到一个新模块Foo::Corge,然后只需要use Foo::Corge在我的每个脚本和模块中移动?

perl module

9
推荐指数
2
解决办法
739
查看次数

Perl:如何在许多独立脚本之间共享大量模块的导入?

我有很多独立的脚本.他们唯一共享的是,他们使用()一大组CPAN模块(每个模块都导出几个函数).我想集中这个模块列表.我发现了几种方法.哪一个是最好的?

  1. 我可以创建SharedModules.pm来导入所有内容,然后使用Exporter手动将所有内容导出到main ::.

  2. 我可以创建以"package main"开头的SharedModules.pm 所以它会直接导入main ::.它似乎工作.这是不好的做法,为什么?

  3. 我可以要求()一个似乎将所有内容导入main ::的sharedmodules.pl.我不喜欢这种方法,因为在mod_perl下,require()不能很好地工作.

第二个看起来对我来说最好,但是我想知道为什么例如Modern :: Perl不能那样工作.

编辑:我认为之前已经问过这个问题.

perl module

7
推荐指数
2
解决办法
357
查看次数


标签 统计

perl ×4

module ×2

cpan ×1

utf-8 ×1