Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Data Structure help

by Enlil (Parson)
on Mar 21, 2003 at 21:19 UTC ( #245010=note: print w/ replies, xml ) Need Help??


in reply to Data Structure help

Heres my take on this:

use strict; use warnings; use Data::Dumper; my %key_hash; local $/ = "\n\n"; while ( <DATA> ) { if ( /^KEY: ([^\n]+)/ ) { my $current_key = $1; while ( m/OID: ([^\n]+)\nNAME: ([^\n]+)|Error Status (.*)/g ) { if ( defined $3 ) { $key_hash{$current_key}{Error_Status} = $3; } else { push @{$key_hash{$current_key}{OID_NAME}}, [$1,$2]; } } } } print Dumper \%key_hash;
__DATA__ KEY: request_1.3.6.1.2.1.2.2.1.12.27 OID: 1.3.6.1.2.1.2.2.1.11.27 NAME: ifInUcastPkts.27 OID: 1.3.6.1.2.1.2.2.1.15.27 NAME: ifInUnknownProtos.27 OID: 1.3.6.1.2.1.2.2.1.14.27 NAME: ifInErrors.27 OID: 1.3.6.1.2.1.2.2.1.13.27 NAME: ifInDiscards.27 OID: 1.3.6.1.2.1.2.2.1.18.27 NAME: ifOutNUcastPkts.27 OID: 1.3.6.1.2.1.2.2.1.17.27 NAME: ifOutUcastPkts.27 OID: 1.3.6.1.2.1.2.2.1.20.27 NAME: ifOutErrors.27 OID: 1.3.6.1.2.1.2.2.1.19.27 NAME: ifOutDiscards.27 OID: 1.3.6.1.2.1.2.2.1.10.27 NAME: ifInOctets.27 OID: 1.3.6.1.2.1.2.2.1.16.27 NAME: ifOutOctets.27 OID: 1.3.6.1.2.1.1.3.0 NAME: sysUpTime.0 OID: 1.3.6.1.2.1.2.2.1.5.27 NAME: ifSpeed.27 OID: 1.3.6.1.2.1.2.2.1.3.27 NAME: ifType.27 Error Status No error KEY: response_1.3.6.1.2.1.2.2.1.12.27 OID: 1.3.6.1.2.1.2.2.1.11.27 NAME: ifInUcastPkts.27 OID: 1.3.6.1.2.1.2.2.1.15.27 NAME: ifInUnknownProtos.27 OID: 1.3.6.1.2.1.2.2.1.14.27 NAME: ifInErrors.27 OID: 1.3.6.1.2.1.2.2.1.13.27 NAME: ifInDiscards.27 OID: 1.3.6.1.2.1.2.2.1.18.27 NAME: ifOutNUcastPkts.27 OID: 1.3.6.1.2.1.2.2.1.17.27 NAME: ifOutUcastPkts.27 OID: 1.3.6.1.2.1.2.2.1.20.27 NAME: ifOutErrors.27 OID: 1.3.6.1.2.1.2.2.1.19.27 NAME: ifOutDiscards.27 OID: 1.3.6.1.2.1.2.2.1.10.27 NAME: ifInOctets.27 OID: 1.3.6.1.2.1.2.2.1.16.27 NAME: ifOutOctets.27 OID: 1.3.6.1.2.1.1.3.0 NAME: sysUpTime.0 OID: 1.3.6.1.2.1.2.2.1.5.27 NAME: ifSpeed.27 OID: 1.3.6.1.2.1.2.2.1.3.27 NAME: ifType.27 Error Status No error
Resulting in a structure like:
$VAR1 = { 'request_1.3.6.1.2.1.2.2.1.12.27' => { 'OID_NAME' => [ [ '1.3.6.1.2.1.2.2.1.11.27', 'ifInUcastPkts.27' ], [ '1.3.6.1.2.1.2.2.1.15.27', 'ifInUnknownProtos.27' ], [ '1.3.6.1.2.1.2.2.1.14.27', 'ifInErrors.27' ], [ '1.3.6.1.2.1.2.2.1.13.27', 'ifInDiscards.27' ], [ '1.3.6.1.2.1.2.2.1.18.27', 'ifOutNUcastPkts.27' ], [ '1.3.6.1.2.1.2.2.1.17.27', 'ifOutUcastPkts.27' ], [ '1.3.6.1.2.1.2.2.1.20.27', 'ifOutErrors.27' ], [ '1.3.6.1.2.1.2.2.1.19.27', 'ifOutDiscards.27' ], [ '1.3.6.1.2.1.2.2.1.10.27', 'ifInOctets.27' ], [ '1.3.6.1.2.1.2.2.1.16.27', 'ifOutOctets.27' ], [ '1.3.6.1.2.1.1.3.0', 'sysUpTime.0' ], [ '1.3.6.1.2.1.2.2.1.5.27', 'ifSpeed.27' ], [ '1.3.6.1.2.1.2.2.1.3.27', 'ifType.27' ] ], 'Error_Status' => 'No error' }, 'response_1.3.6.1.2.1.2.2.1.12.27' => { 'OID_NAME' => [ [ '1.3.6.1.2.1.2.2.1.11.27', 'ifInUcastPkts.27' ], [ '1.3.6.1.2.1.2.2.1.15.27', 'ifInUnknownProtos.27' ], [ '1.3.6.1.2.1.2.2.1.14.27', 'ifInErrors.27' ], [ '1.3.6.1.2.1.2.2.1.13.27', 'ifInDiscards.27' ], [ '1.3.6.1.2.1.2.2.1.18.27', 'ifOutNUcastPkts.27' ], [ '1.3.6.1.2.1.2.2.1.17.27', 'ifOutUcastPkts.27' ], [ '1.3.6.1.2.1.2.2.1.20.27', 'ifOutErrors.27' ], [ '1.3.6.1.2.1.2.2.1.19.27', 'ifOutDiscards.27' ], [ '1.3.6.1.2.1.2.2.1.10.27', 'ifInOctets.27' ], [ '1.3.6.1.2.1.2.2.1.16.27', 'ifOutOctets.27' ], [ '1.3.6.1.2.1.1.3.0', 'sysUpTime.0' ], [ '1.3.6.1.2.1.2.2.1.5.27', 'ifSpeed.27' ], [ '1.3.6.1.2.1.2.2.1.3.27', 'ifType.27' ] ], 'Error_Status' => 'No error' } };

hope this helps..

You might want to take a look at perldsc

-enlil


Comment on Re: Data Structure help
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2015-07-07 05:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls