Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need 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


In reply to Re: Data Structure help by Enlil
in thread Data Structure help by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-23 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found