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

In reply to Not able to retrieve hash value outside the function by aniammu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.