1

vsphere perl sdk 5.5版安装在centos 7 64位机器上

以下 simpleclient.pl(https://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.perlsdk.pg.doc/viperl_modscripts.4.2.html#990705)脚本抛出错误“length() used在 /usr/lib64/perl5/IO/Compress/Zlib/Extra.pm 第 198 行的 @array 上(您的意思是“标量(@array)”吗?)。在 centos-7 64 位机器上。

root@localhost vsphere_perl_exp]# cat simpleclient.pl
#!/usr/bin/perl
use strict;
use warnings;
use VMware::VIRuntime;

my %opts = (
    entity => {
    type => "=s",
    variable => "VI_ENTITY",
    help => "ManagedEntity type: HostSystem, etc",
    required => 1
    },
    );
Opts::add_options(%opts);
Opts::parse();
Opts::validate();

Util::connect();

# Obtain all inventory objects of the specified type
my $entity_type = Opts::get_option('entity');
my $entity_views = Vim::find_entity_views(
    view_type => $entity_type);


[root@localhost vsphere_perl_exp]# perl --version

This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 25 registered patches, see perl -V for more detail)

Copyright 1987-2012, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

使用调试选项运行 perl 在第 11 行停止,

[root@localhost vsphere_perl_exp]# perl -d ./simpleclient.pl --server 15.218.113.152 --username root --password 'secret' --entity HostSystem

Loading DB routines from perl5db.pl version 1.37
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(./simpleclient.pl:6):    my %opts = (
main::(./simpleclient.pl:7):        entity => {
main::(./simpleclient.pl:8):        type => "=s",
main::(./simpleclient.pl:9):        variable => "VI_ENTITY",
main::(./simpleclient.pl:10):       help => "ManagedEntity type: HostSystem, etc",
main::(./simpleclient.pl:11):       required => 1
  DB<1> main::(./simpleclient.pl:14):   Opts::add_options(%opts);
  DB<1> 

我是 perl 的新手,如何调试这个脚本?

4

2 回答 2

4

这不是抛出异常;这是正在打印的警告。

IO::Compress::Zlib::Extra 包含代码

for (my $ix = 0; $ix <= length(@$data) -1 ; $ix += 2)

它已在 2.042(2011 年 11 月 17 日)中修复

for (my $ix = 0; $ix <= @$data -1 ; $ix += 2)

更改日志引用票证7232972505,其中第一个显示了该错误的影响。除了在使用更新版本的 Perl 时看到消息的烦恼之外,这个错误实例是相当无害的。

升级:

sudo cpan IO::Compress::Zlib::Extra
于 2014-10-20T15:28:51.557 回答
0

要获取数组的长度:

my $length = scalar @array;

要获取字符串的长度:

my $length = length("my string");

希望这可以帮助。

于 2014-10-20T12:03:45.167 回答