是否有任何 Perl 模块可以阻止我向任何可能失败的内容添加“or die”?
我正在编写运行各种外部命令以及可能失败的各种文件系统命令的代码。
有没有任何模块可以让我免去向可能失败的任何内容添加 or die
的麻烦?
我希望能够将以下内容包装在某些内容中,而不是:
mkdir $dirname or die "can't create directory $dirname";
system("some external command") or die "can run some external command";
我得到:
some_wrapper_code {
mkdir $dirname;
system("some external command");
}
这样,如果 mkdir
失败,它会告诉我失败发生在 mkdir
中>,如果 system
失败,它会告诉我故障发生在 system
中。
I'm writing code that runs all sorts of external commands as well as various filesystem commands that can fail.
Is there any module that can save me the trouble of adding or die
to anything that can fail?
I'd like to be able to wrap the following in something so that instead of:
mkdir $dirname or die "can't create directory $dirname";
system("some external command") or die "can run some external command";
I get:
some_wrapper_code {
mkdir $dirname;
system("some external command");
}
such that if mkdir
fails it'll tell me that the failure was in mkdir
, and if system
fails it'll tell me that the failure was in system
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。查看 CPAN 中的
autodie
。来自文档:
Yep. Check out
autodie
from CPAN.From the docs: