【发布时间】:2021-04-30 23:21:40
【问题描述】:
my $sth = $dbh->prepare(q{
INSERT INTO sales (product_code, qty, price) VALUES (?, ?, ?)
}) or die $dbh->errstr;
while (<>) {
chomp;
my ($product_code, $qty, $price) = split /,/;
$sth->execute($product_code, $qty, $price) or die $dbh->errstr;
}
$dbh->commit or die $dbh->errstr;
我不想在控制台上显示来自 $sth->execute 的 stderr。如何抑制它?
【问题讨论】:
-
这能回答你的问题吗? Perl: How to "die" with no error message?
-
删除 die $sth->execute($product_code, $qty, $price) 后,我想从 $sth->execute 抑制 stderr,控制台上不应打印任何错误
-
可以通过编写
$SIG{__WARN__}挂钩在很大程度上控制流向STDERR的内容。请参阅 perlvar 中的%SIG哈希。 (但我不确定你到底在问什么......) -
请考虑其他人可能想要这些错误,尽管在您的用例中您不需要。这可能意味着不理会它并将标准输出重定向到空设备。但是,当您需要时,警告就会出现。