如何处理错误“非HASH参考”?

时间:2012-07-23 14:47:41

标签: perl cpan strawberry-perl

我正在尝试执行用户创建的Perl脚本,

usage: my.pl <type> <stats> [-map <map>] <session1> [session2] 
Produces statistics about the session from a Wireshark .pcap file where:
<type> is the type of data in the pcap file (wlan, ethernet or ip)
<stats> is the output file to write notable information
<session> is the pcap input file or a folder containing pcaps (recursive)

但它失败并出现以下错误。

        $perl my.pl ethernet pa.xls google.pcap
        Processing pcap trace (TCP):
        Not a HASH reference at folder/httpTrace.pm line 654.

这是调试控制台 -

    Not a HASH reference at folder/httpTrace.pm line 654. at folder/httpTrace.pm line 654
        folder::httpTrace.pm::readHttp('HASH(0x2306d38)', undef) called at my.pl line 56
        main::__processSession('google.pcap') called at my.pl line 35 Debugged program terminated.  

httpTrace.pm:最后一行#654

    sub readHttp($@)
    {
        my ($conntable, $map) = @_;
        my $http_req_id = 0;
        my $pipelining = 0;

        my $mapc;
        my @allReq;
        my @allRep;
        if( defined( $map ) ) {
            $mapc = $map->clone();
        }
    foreach my $connect ( sort { $pa->{'id'} <=> $pb->{'id'} } values( %{ $conntable } ) ) {

my.pl中的第56行:

    my $stats = Pcapstats::HTTP::readHttp( \%tcp_stream, $map );

还有map.pm&amp;在my.pl中的用法为

    my $map;
    if( $ARGV[0] eq '-map' ) {
        shift( @ARGV );
        $map = Pcapstats::Map->new( shift( @ARGV ) );
    }

1 个答案:

答案 0 :(得分:0)

在您的文件httpTrace.pm中,您有这一行

foreach my $connect ( sort { $pa->{'id'} <=> $pb->{'id'} } values( %{ $conntable } ) ) {

我想知道$pa$pb是什么?除非您将它们设置为其他位置,否则它们将被定义为未定义并将为您提供使用未初始化的值错误。无论哪种方式,你都不会进行排序。

但这并不能解释 Not a HASH reference 错误,这很可能是因为$conntable不是您认为的错误。如果未定义它将不会导致错误,因为autovivication将自动创建一个空哈希,因此它可能是一个简单的字符串或数字,或者可能是一个数组引用。

如果您想显示设置$conntable的代码,那么我们可以提供更多帮助。

相关问题