I sent a message to this forum nearly two weeks ago asking for hints about how to convert a particular MUMPS construct into a Perl construct. I recevied several helpful answers and have been able to implement a solution. I'd like to thank everyone who kindly took the time to respond. Here is the solution I have implemented:
The application in question is an SNMP program that is querying routers and switches for various data. A number of SNMP variables, or Object Identifiers (OIDs), are placed into an SNMP message and a GetBulk query is sent to the device in question. The returned answer is placed in a hash that has all the descendants of the OIDs as the key and the contents of the OIDs as the value. There may be 10 entries returned, there may be 1000, but the large sized returns are rare and they don't get much bigger. The problem I was trying to resolve was how to take each of the original OIDs and find all of their descendants in the hash. Answer: A single for loop is executed against the sorted hash (the Net::SNMP module provides a means to lexically sort SNMP OIDs). An array is built with each key found. A second hash is also built that has the original OIDs as its keys and the starting and ending points within the array of the descendants of that OID. I am able to duplicate everything I was doing with the MUMPS $ORDER function by using this construct. Here is a brief example: Original OIDs in the SNMP query: $ifDescr = '1.3.6.1.2.1.2.2.1.2'; $ifInOctets = '1.3.6.1.2.1.2.2.1.10'; $ifOutOctets = '1.3.6.1.2.1.2.2.1.16'; Resulting answer in hash (after sorting): 1.3.6.1.2.1.2.2.1.2.1 => FastEthernet0/0 1.3.6.1.2.1.2.2.1.2.2 => FastEthernet0/1 1.3.6.1.2.1.2.2.1.2.3 => FastEthernet0/1/0 1.3.6.1.2.1.2.2.1.2.4 => FastEthernet0/1/1 1.3.6.1.2.1.2.2.1.2.5 => FastEthernet0/1/2 1.3.6.1.2.1.2.2.1.2.6 => FastEthernet0/1/3 1.3.6.1.2.1.2.2.1.2.7 => Serial0/2/0 1.3.6.1.2.1.2.2.1.2.8 => Serial0/2/1 1.3.6.1.2.1.2.2.1.2.10 => Null0 1.3.6.1.2.1.2.2.1.2.11 => Vlan1 1.3.6.1.2.1.2.2.1.2.14 => Tunnel1 1.3.6.1.2.1.2.2.1.2.15 => Dialer1 1.3.6.1.2.1.2.2.1.2.16 => Tunnel207 1.3.6.1.2.1.2.2.1.2.17 => Tunnel1000 1.3.6.1.2.1.2.2.1.2.18 => Loopback7 1.3.6.1.2.1.2.2.1.10.1 => 874730985 1.3.6.1.2.1.2.2.1.10.2 => 1811311832 1.3.6.1.2.1.2.2.1.10.3 => 0 1.3.6.1.2.1.2.2.1.10.4 => 0 1.3.6.1.2.1.2.2.1.10.5 => 0 1.3.6.1.2.1.2.2.1.10.6 => 0 1.3.6.1.2.1.2.2.1.10.7 => 0 1.3.6.1.2.1.2.2.1.10.8 => 0 1.3.6.1.2.1.2.2.1.10.10 => 810178717 1.3.6.1.2.1.2.2.1.10.11 => 0 1.3.6.1.2.1.2.2.1.10.14 => 7028243 1.3.6.1.2.1.2.2.1.10.15 => 976914585 1.3.6.1.2.1.2.2.1.10.16 => 2208958682 1.3.6.1.2.1.2.2.1.10.17 => 330703546 1.3.6.1.2.1.2.2.1.10.18 => 0 1.3.6.1.2.1.2.2.1.16.1 => 2555943293 1.3.6.1.2.1.2.2.1.16.2 => 1303511954 1.3.6.1.2.1.2.2.1.16.3 => 0 1.3.6.1.2.1.2.2.1.16.4 => 0 1.3.6.1.2.1.2.2.1.16.5 => 0 1.3.6.1.2.1.2.2.1.16.6 => 0 1.3.6.1.2.1.2.2.1.16.7 => 0 1.3.6.1.2.1.2.2.1.16.8 => 0 1.3.6.1.2.1.2.2.1.16.10 => 0 1.3.6.1.2.1.2.2.1.16.11 => 0 1.3.6.1.2.1.2.2.1.16.14 => 27898498 1.3.6.1.2.1.2.2.1.16.15 => 679742996 1.3.6.1.2.1.2.2.1.16.16 => 1497913589 1.3.6.1.2.1.2.2.1.16.17 => 329425921 1.3.6.1.2.1.2.2.1.16.18 => 43584486 These keys are then placed in an array indexed from 0 to n. The "original OID" hash then looks like the following: $OID{$ifDescr} = "0,17" $OID{$ifInOctets} = "18,35" $OID{$ifOutOctets} = "36,53" I can now find the answers for each variable I queried, from the beginning forward or the end backward, with only one scan of the hash table. Thanks again, everyone. One final note: I did take a look at Language-Mumps-1.07. This is based on a very old, primitive flavor of MUMPS and, when I wrote a very small test program and ran it agains this "translator" it returned the wrong results. I don't recommend anyone using it. Mark Berryman