Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a reference to a hash, now what?

Status
Not open for further replies.

CRCarl

Programmer
Dec 29, 2007
2
US
All -
I'm trying to do something I haven't done before. It looks like the perl module I am using is returning a reference to a hash. I know that the actual returned data is an XML document. What is the best way to actually get to the XML document from the hash reference? I've tried XML::Twig parse->(%hash) but that didn't work. The code and results are just below.

Thanks!

use NaServer;

my $host = shift;
my $user = shift;
my $pw = shift;

if ($user eq "") {
print("Usage: You need - host user passwd");
exit(-1);
}

my $s = NaServer->new($host, 1, 3);

$s->set_style(LOGIN_PASSWORD);
$s->set_admin_user($user, $pw);
$s->set_transport_type(
NA_SERVER_TRANSPORT_HTTPS);

my %out = $s->invoke(
"aggr-list-info");

@keys = keys %out;
@values = values %out;
while ($#keys >= 0) {
print pop(@keys), '=', pop(@values), "\n";
}
0;

Returns -

NaElement=HASH(0x83e8640)=


 
You mean the "invoke" method.
Code:
my $hashref = $s->invoke( 'aggr-list-info' );

# get keys of the hash referred to by $hashref
my @keys = keys %$hashref;

# get an element
my $element = $hashref->{ key_name };
 
Alright - so that helped a little, now it looks like I am getting references to arrays? Here is your code modified to output to the cli -


my $hashref = $s->invoke( 'disk-list-info' );

# get keys of the hash referred to by $hashref
my @keys = keys %$hashref;

print "-------keys----------\n";
foreach (@keys) {
print "$_\n";
}
print "-----elements--------\n";
foreach (@keys) {
my $element = $hashref->{$_};
print "$element\n";
}



-------keys----------
content
name
children
attrvals
attrkeys
-----elements--------

results
ARRAY(0x83f4da0)
ARRAY(0x83db530)
ARRAY(0x83dbfa4)
 
print @{$element},"\n";

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top