gpt4 book ai didi

perl - 调试 perl 脚本

转载 作者:行者123 更新时间:2023-12-04 05:57:24 28 4
gpt4 key购买 nike

我不知道 perl,但我需要调试我正在使用的应用程序所需的 perl 脚本,这是我得到的错误:

Unable to recognise encoding of this document at /usr/lib/perl5/vendor_perl/5.8.8/XML/SAX/PurePerl/EncodingDetect.pm line 9

问题是,这个脚本无法弄清楚文件的编码是什么。我想知道的是,那是哪个文件。我无法找到堆栈跟踪的方法。这是稍微修剪的脚本:
package XML::SAX::PurePerl; # NB, not ::EncodingDetect!

use strict;

sub encoding_detect {
my ($parser, $reader) = @_;

my $error = "Invalid byte sequence at start of file";
my $data = $reader->data;
if ($data =~ /^\x00\x00\xFE\xFF/) {
# BO-UCS4-be
$reader->move_along(4);
$reader->set_encoding('UCS-4BE');
return;
} .. tons of if else statements

warn("Unable to recognise encoding of this document");
return;

我检查了,但这个阅读器对象没有名称或路径属性。我可以控制这个脚本,所以我可以在必要时对其进行修改。任何帮助表示赞赏。

编辑:我已经找到了问题,直到我尝试使用的应用程序中的这一行:
my @array = SystemImager::HostRange::expand_groups($clients);

最佳答案

如果您使用 Carp 模块和 confess方法,你会得到一个堆栈回溯:

use Carp;

confess "Something went horribly wrong" if ($something == $wrong);
这在函数内部(在模块中)最有用,但它有帮助。但是,听起来好像您正在使用的代码正在报告错误,因此您可能无法将其发送到 croak适合您,但您应该阅读 Carp 的手册,其中部分内容是:

Forcing a Stack Trace

As a debugging aid, you can force Carp to treat a croak as a confess and a carp as a cluck across all modules. In other words, force a detailed stack trace to be given. This can be very helpful when trying to understand why, or from where, a warning or error is being generated.

This feature is enabled by 'importing' the non-existent symbol 'verbose'. You would typically enable it by saying

perl -MCarp=verbose script.pl

or by including the string -MCarp=verbose in the PERL5OPT environment variable.

Alternat[iv]ely, you can set the global variable $Carp::Verbose to true.



正如 daxim 所建议的那样在评论中,还可以考虑 Carp::Always :
use Carp::Always;

makes every warn() and die() complain loudly in the calling package and elsewhere. More often used on the command line:

perl -MCarp::Always script.pl

XML::SAX::PurePerl 的纯 Perl 实现被其维护者标记为“慢”。您或许应该考虑使用许多其他基于 XS 的 SAX 模块之一,尤其是提供自动编码检测的模块。

关于perl - 调试 perl 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9346258/

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