如何在perl中处理异常?
我试图找到clearcase视图的最后访问日期,perl脚本如下所示如何在perl中处理异常?,perl,clearcase,Perl,Clearcase,我试图找到clearcase视图的最后访问日期,perl脚本如下所示 @Property = `cleartool lsview -prop $viewtag ` ; foreach $property (@Property) { $last_accessed = $property if ( $property =~ /^Last accessed / ); # | cut -b 15-24 | awk -F '-' '{ print $3
@Property = `cleartool lsview -prop $viewtag ` ;
foreach $property (@Property)
{
$last_accessed = $property if ( $property =~ /^Last accessed / );
# | cut -b 15-24 | awk -F '-' '{ print $3"/"$2"/"$1 }'
}
我面临的问题是,如果cleartool命令失败,perl脚本将退出。我希望perl继续,即使cleartool返回错误
BRs
Mani.您可以按照“”中的建议尝试使用“”
另一种方法是使用cleartool命令eval
eval { @Property = `cleartool lsview -prop $viewtag` };
if ($@) {
warn "Oh no! [$@]\n";
}
简单而原始的方法是将可能失败的代码放入eval块中:
eval { @Property = `cleartool lsview -prop $viewtag ` };
这样,即使cleartool失败,您的Perl脚本也将继续
正确的方法是使用适当的模块,如。该错误将在变量$\中的catch块内可用
try {
@Property = `cleartool lsview -prop $viewtag `;
}
catch {
warn "cleartool command failed with $_";
};
如果
@Property
出现故障,该怎么办?对于无/低CPAN站点,“原始”方式是保证工作的方式。