相关疑难解决方法(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
查看次数

如何使用一个"使用""使用"多个模块?

我想在我的所有程序中使用一些包和一些编译指示,例如:

use 5.014;
use warnings;
use autodie;
use My::ModuleA::Something;
use ModuleB qw(Func1 Func2);
Run Code Online (Sandbox Code Playgroud)

我不想在每个模块中重复自己,所以寻找一种方法如何制作一个包,例如My::Common包含上述包的内容以及我的程序中只包含:

use My::Common;
say Func1("hello"); #say enabled and Func1 imported in the My::Common
Run Code Online (Sandbox Code Playgroud)

怎么实现这个?

这是阅读preldoc -f use,perldoc perlmodlib所以我认为我必须"有点"用BEGIN加上需要和导入,但绝对不知道如何.


更新:我已经尝试了基本的东西.

require- 我的prg.pl程序.

require 'mymods.pl';
$var = "hello";
croak "$var\n";
Run Code Online (Sandbox Code Playgroud)

mymods.pl包含

use strict;
use feature 'say';
use Carp qw(carp croak cluck);
1;
Run Code Online (Sandbox Code Playgroud)

不工作.得到错误:

$ perl prg.pl 
String found where operator expected at prg.pl line 3, near "croak "$var\n""
    (Do you …
Run Code Online (Sandbox Code Playgroud)

perl

13
推荐指数
2
解决办法
2557
查看次数


标签 统计

perl ×3

cpan ×1

utf-8 ×1