且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Perl中有条件地导入包?

更新时间:2022-06-21 21:35:50

你可以使用要求在运行时加载模块, eval 以捕获可能的异常:

You can use require to load modules at runtime, and eval to trap possible exceptions:

eval {
    require Foobar;
    Foobar->import();
};  
if ($@) {
    warn "Error including Foobar: $@";
}

另请参阅perldoc 使用

See also perldoc use.