本文介绍了如果打开文件失败,必须使用 die 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大多数时候,我做这样的事情:
Most of time, I do something like this:
open FH, ">file.txt" or die "Cann't open file: $!";
必须使用die
吗?如果我想让我的脚本继续运行(如果文件无法打开,只需忽略错误),我该怎么办?
Does die
have to be used? If I want my script to continue (and simply ignore the error if the file cannot be opened), what should I do?
推荐答案
你可能想做类似的事情
if(open my $fh, ">", "file.txt") {
# do stuff with file
close $fh;
}
else {
# do stuff without file
}
这篇关于如果打开文件失败,必须使用 die 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!