help with an anonymous array of anonymous hashes

  • Thread starter noeldamonmiller
  • Start date
N

noeldamonmiller

All,



Here's the scenario. There is an anonymous array used to store
netstat information (from a system call) as follows (why? I don't know
a better way to get it):

(@elements has netstat info split to enable the info below to work
correctly)

@connection = {
"UID" => "$elements[6]",
"PID" => "$elements[8]",
"IPadd" => "$elements[4]"
};

Now, I can access the values of the elements ie, get the UID # and PID#
as follows

foreach $href ( @connection ) {
foreach $role ( keys %$href ) {
print "the monitor href is $href->{$role}\n"
}
}

with this kind of output:


the monitor href is 11743/kopete
the monitor href is 500
the monitor href is 216.155.193.164:5050
the monitor href is 11169/smbd
the monitor href is 0
the monitor href is 192.168.0.14:1036

so, in summary, as far as I can tell we have:

@connection with hash0, hash1, hash2, etc. each one of them referred to
individually as $href

and %$href with 11743/kopete, 500, 216.155.193.164:5050 (UID,PID,IPadd)

my question is, how do I access each value of these elements
individually? I can do it the cheesy way by doing the foreach loops
above and get for instance an array of IPaddresses:

foreach $href ( @connection ) {
foreach $role ( keys %$href ) {
if ($role eq "IPadd") { push @noport_ipadd, $href->{$role}; }

}
}

What I want to do is something like the pseudo-code below, only
syntactically correct:

foreach $href ( @connection ){ push @noport_ipadd, %$href->$role[2];}


I think I'm missing something with regards to dereferencing this stuff,
but unsure.

Thank you very much for any help.

Bigoldrock
 
N

noeldamonmiller

Thanks Jim,


Quite right about the whole thing. It sure helps to have someone
else dig into this.


Thanks,

Noel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top