aniammu has asked for the wisdom of the Perl Monks concerning the following question:
I have a requirement where in i have a lab page and need to retrieve the value of lab name and ip address. My code is as below
#!/usr/bin/perl -w use LWP::UserAgent; use HTTP::Request; use HTML::TableExtract; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; require 'dumpvar.pl'; my $ua = LWP::UserAgent->new(timeout => 10); my $url = 'https://<link for lab page>'; my $request = HTTP::Request->new('GET',$url); my $response = $ua->request($request); our %hash = (); if ($response->is_success){ our $te = new HTML::TableExtract( headers => ['Hostname','IP'] ); $te->parse($response->content); foreach our $ts ($te->table_states) { print "The value of ESXI hosts \n"; foreach our $row ($ts->rows) { print (join("\t", @$row)."\n"); %hash=@$row; } } } else { print "Error: ".$response->status_line."\n"; } while (($key, $value) = each(%hash)) { print "Key : $key & value : $value\n"; }
I am getting below output
#aniammu>perl withLWP.pl Parsing of undecoded UTF-8 will give garbage when decoding entities at + C:/Perl64/lib/HTML/TableExtract.pm line 204. The value of ESXI hosts esx1 0.0.1.1 esx2 1.1.1.1 esx3 2.2.2.2 Key : esx3 & value : 2.2.2.2 #aniammu>
Actually my requirement is to fetch the all the esx names and ip's
Pls help me to resolve this issue. My Current output is as below
Key : esx3 & value : 2.2.2.2
Required output
Key : esx1 & value : 0.0.1.1 Key : esx2 & value : 1.1.1.1 Key : esx3 & value : 2.2.2.2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Not able to retrieve hash value outside the function
by Corion (Patriarch) on Dec 21, 2015 at 10:22 UTC | |
by Anonymous Monk on Dec 22, 2015 at 04:21 UTC | |
|
Re: Not able to retrieve hash value outside the function
by Preceptor (Deacon) on Dec 21, 2015 at 10:23 UTC | |
by aniammu (Novice) on Dec 22, 2015 at 04:22 UTC |