gpt4 book ai didi

perl - Perl 的 "include"-esque 函数

转载 作者:行者123 更新时间:2023-12-04 16:40:52 24 4
gpt4 key购买 nike

我有一个函数,我想在两个不同的 Perl 脚本中定义,但不喜欢同时编辑这两个脚本。有没有办法include它(如在 PHP 中)来自外部文件?

功能文件:

sub test {

}

文件 1:
include func_file;
foo();
bar();
test();

文件 2:
include func_file;
blah();
test();

最佳答案

狭隘地回答这个问题:

是的,您可以使用 require('filename') 包含文件功能。

笼统地回答这个问题:

Perl 通过其包机制具有完整的函数定义和导出机制。这是described in perlmod .您应该真正使用这种机制,因为您最终可以将模块打包成一个 CPAN 模块,并使其可供其他人使用,或者简单地自己安装在其他系统上。

关于perl - Perl 的 "include"-esque 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8514785/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com