Reputation: 21877
The vsphere perl sdk version 5.5 is installed on centos 7 64 bit machine
The following simpleclient.pl(https://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.perlsdk.pg.doc/viperl_modscripts.4.2.html#990705) script throws error "length() used on @array (did you mean "scalar(@array)"?) at /usr/lib64/perl5/IO/Compress/Zlib/Extra.pm line 198." on centos-7 64 bit machine.
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.
Running perl with debug option stops at line 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>
I am newbie to perl, How to debug this script?
Upvotes: 1
Views: 5544
Reputation: 385917
It's not an exception being thrown; it's a warning being printed.
IO::Compress::Zlib::Extra contained the code
for (my $ix = 0; $ix <= length(@$data) -1 ; $ix += 2)
It was fixed in 2.042 (Nov 17th, 2011)
for (my $ix = 0; $ix <= @$data -1 ; $ix += 2)
The change log references tickets 72329 and 72505, the first of which shows what effect the bug has. This instance of the bug is rather harmless save for the annoyance of seeing the message when using newer versions of Perl.
To upgrade:
sudo cpan IO::Compress::Zlib::Extra
Upvotes: 4
Reputation: 354
To get the length of an array:
my $length = scalar @array;
To get the length of a string:
my $length = length("my string");
Hope this helps.
Upvotes: 0