Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (18)
    As of 2014-09-18 12:29 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (113 votes), past polls