Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Dynamic array names

by CiceroLove (Monk)
on Feb 09, 2001 at 19:02 UTC ( #57464=note: print w/replies, xml ) Need Help??


in reply to Dynamic array names

I guess I didn't give enough information (I'm generally as hard to start as a lawnmower in winter). I am actually walking the MIB tree for some MIBs that are defined in our snmpd.conf as processes. As such, the results of the walk give us , for example:
1.1:1 1.2:2 1.3:3 2.1:httpd 2.2:sendmail 2.3:portmap 3.1:5 3.2:0 3.3:0 4.1:0 4.2:0 4.3:0 5.1:3 5.2:0 5.3:0 101.1:My error message for httpd 101.2:My error message for sendmail 101.3:My error message for portmap
This is unchangeable in terms of order. The value before the ':' is the trail of the OID and the value after si the actual data I need in my script to use. But my problem is that the number fo services could change on the fly so I won't know how many services are being monitored. As a result, I need ot be able to take every instance of 2.x:$serviceName and create an array of the values. My approach is to find out how many services and then go back through the list leapgfrogging through the list to get the values which match up with the service. Does that make sense? Me, either. Thanks again. CiceroLove

Replies are listed 'Best First'.
Re: Re: Dynamic array names
by Masem (Monsignor) on Feb 09, 2001 at 20:43 UTC
    OOTOMH:
    my %serviceHash;
    while (<INPUT>) {
        /^(\d*)\.(\d*)\:(\S*)$/;
        if ( !defined( $serviceHash{ $1 } ) ) {
            my @array = ();
            $serviceHash{ $1 } = \@array;
        }
        $($serviceHash{ $1 })[ $2 ] = $3;
    }
    
    You can then do a foreach over the keys of the hash, and do the necessary processing from there. (Update: damn those gt and lt's!)
      If you wish to paste in code, please use the <code>...</code></code> tags. That not only gives easy formatting, but it also makes your code available from clicking on "d/l code".

      UPDATE
      Since tye complained, here is an example of what the CODE tag looks like:

      foreach (split //, "Just another Perl hacker,\n") { print; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://57464]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2021-09-19 10:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?