in reply to Extracting xml data and using them for SNMP

That's a LOT of code for what seems to be such a minor task. All those files you open and close, do you really need them? Wouldn't simple arrays and hashes and perhaps some Caching be better? I will admit that when i first started Perl, i had a bad habit of looping many times instead of just once or twice. Unrelated to that, one particular item that really bothers me is this:

my $ref = eval { XMLin($xmlfile) }; #see if open worked if ($@) { print "XML Read ERROR"; } else { ... }
Why are you bypassing the errors reported from XML::Simple in this manner? Seems to me that if the file cannot be parsed then you don't need to be continuing execution. Not to mention that XML::Simple will return meaningful messages as to why the file did not parse. By trapping the die you have no clue as to what went wrong.

Finally, unless you provide some example XML, we can't really try your code out. But i still think you could trim this down to under 40 lines. ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Extracting xml data and using them for SNMP
by theroninwins (Friar) on Sep 03, 2004 at 08:27 UTC
    <?xml version="1.0" encoding="UTF-8" ?> - <CMData> <CMServer>BIBAS03</CMServer> <CreatedAt>Tue Aug 24 09:09:41 GMT+02:00 2004</CreatedAt> <SchemaVersion>1.0</SchemaVersion> <Heading>Topology Data</Heading> - <Layer2Details> - <Device> <DeviceName>LWL-H91-CW-4-5-4.bc.de.bic</DeviceName> <IPAddress>148.192.59.254</IPAddress> <DeviceState>Reachable</DeviceState> <DeviceType>C2950G-24</DeviceType> - <Neighbors> - <Neighbor> <NeighborIPAddress>148.192.22.22</NeighborIPAddress> <NeighborDeviceType>C6506</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Gi0/2</LocalPort> <RemotePort>3/3</RemotePort> </Neighbor> - <Neighbor> <NeighborIPAddress>148.192.22.18</NeighborIPAddress> <NeighborDeviceType>C6509</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Gi0/1</LocalPort> <RemotePort>3/3</RemotePort> </Neighbor> - <Neighbor> <NeighborIPAddress>148.192.59.253</NeighborIPAddress> <NeighborDeviceType>C2950-24</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Fa0/1</LocalPort> <RemotePort>Fa0/1</RemotePort> </Neighbor> - <Neighbor> <NeighborIPAddress>148.192.59.252</NeighborIPAddress> <NeighborDeviceType>C2950-24</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Fa0/2</LocalPort> <RemotePort>Fa0/1</RemotePort> </Neighbor> </Neighbors> </Device> - <Device> <DeviceName>stp-g91-cw-2-1-3.bc.de.bic</DeviceName> <IPAddress>148.192.166.249</IPAddress> <DeviceState>Reachable</DeviceState> <DeviceType>C2950-24</DeviceType> - <Neighbors> - <Neighbor> <NeighborIPAddress>148.192.166.254</NeighborIPAddress> <NeighborDeviceType>C2950G-24</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Fa0/1</LocalPort> <RemotePort>Fa0/3</RemotePort> </Neighbor> </Neighbors> </Device> - <Device> <DeviceName>stp-k41-cw-e-2-2.bc.de.bic</DeviceName> <IPAddress>148.192.86.253</IPAddress> <DeviceState>Reachable</DeviceState> <DeviceType>C2924XLV</DeviceType> - <Neighbors> - <Neighbor> <NeighborIPAddress>148.192.86.254</NeighborIPAddress> <NeighborDeviceType>C2950G-24</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Fa0/1</LocalPort> <RemotePort>Fa0/4</RemotePort> </Neighbor> </Neighbors> </Device> - <Device> <DeviceName>stp-j51-cw-1-2-2.bc.de.bic</DeviceName> <IPAddress>148.192.88.253</IPAddress> <DeviceState>Reachable</DeviceState> <DeviceType>C2950-24</DeviceType> - <Neighbors> - <Neighbor> <NeighborIPAddress>148.192.88.254</NeighborIPAddress> <NeighborDeviceType>C2950G-24</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Fa0/1</LocalPort> <RemotePort>Fa0/1</RemotePort> </Neighbor> </Neighbors> </Device> - <Device> <DeviceName>lwl-h81-cw-u-1-1.bc.de.bic</DeviceName> <IPAddress>148.192.74.254</IPAddress> <DeviceState>Reachable</DeviceState> <DeviceType>C2950G-24</DeviceType> - <Neighbors> - <Neighbor> <NeighborIPAddress>148.192.74.251</NeighborIPAddress> <NeighborDeviceType>C2950-24</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Fa0/13</LocalPort> <RemotePort>Fa0/1</RemotePort> </Neighbor> - <Neighbor> <NeighborIPAddress>148.192.22.14</NeighborIPAddress> <NeighborDeviceType>C6506</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Gi0/2</LocalPort> <RemotePort>4/1</RemotePort> </Neighbor> - <Neighbor> <NeighborIPAddress>148.192.22.10</NeighborIPAddress> <NeighborDeviceType>C6506</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Gi0/1</LocalPort> <RemotePort>4/1</RemotePort> </Neighbor> - <Neighbor> <NeighborIPAddress>148.192.74.249</NeighborIPAddress> <NeighborDeviceType>C2950-24</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Fa0/6</LocalPort> <RemotePort>Fa0/1</RemotePort> </Neighbor> - <Neighbor> <NeighborIPAddress>148.192.74.250</NeighborIPAddress> <NeighborDeviceType>C2950-24</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Fa0/5</LocalPort> <RemotePort>Fa0/1</RemotePort> </Neighbor> - <Neighbor> <NeighborIPAddress>148.192.74.253</NeighborIPAddress> <NeighborDeviceType>C2950C-24</NeighborDeviceType> <Link>Point to Point link</Link> <LocalPort>Fa0/24</LocalPort> <RemotePort>Fa0/1</RemotePort> </Neighbor> </Neighbors> </Device> </Layer2Details> </CMData>
    Here is some XML to try the code with sorry about not posting it before