gpt4 book ai didi

perl - 使用假文件名时,Perl Template-Toolkit不会报告错误

转载 作者:行者123 更新时间:2023-12-03 09:07:03 24 4
gpt4 key购买 nike

在Perl的Template Toolkit中,我得到两个错误而不是一个错误。

local $SIG{__DIE__} = \&fatal;

print template('home.htssdfgsml');

sub template {
# --------------------------------------------------------------
#
my ($file, $vars) = @_;
my ($output, $template);

my $config = {
INCLUDE_PATH => $TEMPLATE_PATH
};
$template = Template->new($config);
$template->process($file, $vars, \$output) || die Template->error;

return $output;
}
sub fatal {
# --------------------------------------------------------------
#
my $msg = shift;

print_header();

print "<p><font face='Tahoma,Arial,Helvetica' size=2>A fatal error has occured:</font></p><blockquote><pre>$msg</pre></blockquote></font></p>\n";
}

我得到的输出有两个错误而不是一个错误:
A fatal error has occured:

file error - home.htssssml: not found


A fatal error has occured:

file error - home.htssssml: not found at /var/path/path/file.pm line
29.

关于如何仅打印一个错误的任何建议?

最佳答案

好吧,如果$ ^ S 显然已将其修复为仅给出一个错误(包括行号),则此返回

sub fatal {
# --------------------------------------------------------------
#
return if $^S;
my $msg = shift;

print_header();

print "<p><font face='Tahoma,Arial,Helvetica' size=2>A fatal error has occured:</font></p><blockquote><pre>$msg</pre></blockquote></font></p>\n";
}

这似乎是错误的代码,因为它会在评估中检查是否死亡。这看起来足够吗?

关于perl - 使用假文件名时,Perl Template-Toolkit不会报告错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18997124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com