不能使用未定义的值作为符号引用 [英] Can't use an undefined value as a symbol reference

查看:22
本文介绍了不能使用未定义的值作为符号引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 API 用于 Palo Alto Networks 软件.该代码应该将用户网络登录的用户名和 IP 地址提交到 Web 界面.

I'm trying to use an API for a Palo Alto Networks software. The code is supposed to submit username and ipaddress of user network logins to a web interface.

当我尝试将 PAN 的 API 与 Windows 机器的示例代码一起使用时,抛出以下异常:

When I try using PANs' API with their sample code for a windows machine the following exception is thrown:

Can't use an undefined value as a symbol reference at
C:/Perl/lib/PAN/API.pm line 179 (#1)

PAN::API::UID::login('PAN::API::UID=HASH(0x7fd113828598)', 'SCU-DSM22/pmmertens', 172.16.6.117) called at API_events.pl line 12

这是 API 文档附带的代码示例:

This is the code-example that comes with the API documentation:

#!/usr/bin/perl -w

use strict;
use PAN::API;

my     $useridagent    = '10.0.0.99'; #I changed this to our PAN server address

my     $useridapi      = PAN::API::UID->new($useridagent);

my     $user           = $ENV{USERDOMAIN}.'/'.$ENV{USERNAME};
my     $ipaddress      = unpack('W4',gethostbyname($ENV{COMPUTERNAME}));

    $useridapi->login($user,$ipaddress);

我已确保正确检索了所有变量.替换文字值也无济于事.谷歌搜索这个错误会发现关于硬引用和软引用的引用,但我在下面的代码中没有看到任何违反这些规则的行为.

I've ensure that all variables are retrieved correctly. Substituting literal values did not help either. Googling this error turned up references about hard and soft references but I don't see any infractions of these rules in the code below.

这是来自 PAN/Api.pm 的代码块.第 179 行是打印开始的地方.

This is the codeblock from PAN/Api.pm. Line 179 is where the print starts.

sub submit () {
    my  $self               = shift;

    use IO::Socket::INET;
    use IO::Socket::SSL;

    my  $socket             = IO::Socket::INET->new(PeerAddr => $self->{server},
                                                PeerPort => $self->{port},
                                                Proto    => 'tcp');

    my  $socketssl          = IO::Socket::SSL->start_SSL(   $socket,
                                                    SSL_version     =>'TLSv1');
    print   $socketssl $self->xml;
            $socketssl->close;
            $socketssl->stop_SSL;
}

推荐答案

IO::Socket::INET 和 IO::Socket::SSL 行都应该进行错误检查.类似的东西:

Both the IO::Socket::INET and IO::Socket::SSL lines should have error checking. Something like:

my $socket = IO::Socket::INET->new(....)
  or die "Failed to create socket: $!"

还有:

my $socketssl = IO::Socket::SSL->start_SSL(...)
  or die "Failed to start SSL: ".IO::Socket::SSL::errstr();

虽然我可能会选择 Carp::confess 而不是死.

Although instead of die I might go with Carp::confess.

这篇关于不能使用未定义的值作为符号引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆