perl抛出错误"长度()用于@array(你的意思是"标量(@array)"?)在/usr/lib64/perl5/IO/Compress/Zlib/Extra.pm第198行。"

时间:2014-10-20 10:08:51

标签: perl vsphere

vsphere perl sdk 5.5版安装在centos 7 64 bit machine

以下simpleclient.pl(https://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.perlsdk.pg.doc/viperl_modscripts.4.2.html#990705)脚本在/ usr / lib64 / perl5 / IO / Compress上抛出错误“length()是否用于@array(你的意思是”标量(@array)“?) /Zlib/Extra.pm第198行。“在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的新手,如何调试这个脚本?

2 个答案:

答案 0 :(得分:4)

它不是一个被抛出的例外;这是一个警告。

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

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

修正于2。0242(2011年11月17日)

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

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

要升级:

sudo cpan IO::Compress::Zlib::Extra

答案 1 :(得分:0)

获取数组的长度:

my $length = scalar @array;

获取字符串的长度:

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

希望这有帮助。