help with an anonymous array of anonymous hashes

Discussion in 'Perl Misc' started by noeldamonmiller@gmail.com, Feb 9, 2005.

  1. Guest

    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
     
    , Feb 9, 2005
    #1
    1. Advertising

  2. Guest

    Thanks Jim,


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


    Thanks,

    Noel
     
    , Feb 10, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Holness

    Hashes of Hashes via subs

    Ben Holness, Oct 5, 2003, in forum: Perl
    Replies:
    8
    Views:
    570
    Ben Holness
    Oct 8, 2003
  2. Steven Arnold

    using hashes as keys in hashes

    Steven Arnold, Nov 23, 2005, in forum: Ruby
    Replies:
    3
    Views:
    166
    Mauricio Fernández
    Nov 23, 2005
  3. kazaam
    Replies:
    12
    Views:
    279
    Matthias Wächter
    Sep 13, 2007
  4. Matt Brooks
    Replies:
    16
    Views:
    229
    Matt Brooks
    Sep 16, 2009
  5. Tim O'Donovan

    Hash of hashes, of hashes, of arrays of hashes

    Tim O'Donovan, Oct 27, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    217
Loading...

Share This Page