尝试在Perl中使用Module并在模块不可用时打印消息 [英] try to use Module in Perl and print message if module not available
本文介绍了尝试在Perl中使用Module并在模块不可用时打印消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够在Perl中执行此操作(下面的代码是Python lol)
I wanted to be able to do this in Perl (the code below is Python lol)
try:
import Module
except:
print "You need module Module to run this program."
有没有人知道怎么做?
推荐答案
eval "use Module; 1" or die "you need Module to run this program".
或
require Module or die "you need Module to run this program";
Module->import;
或
use Module::Load;
eval { load Module; 1 } or die "you need Module to run this program";
你可以找到 Module :: Load on CPAN 。
这篇关于尝试在Perl中使用Module并在模块不可用时打印消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文