Maybe a different hash approach? :

use warnings; use strict; use Data::Dumper qw/Dumper/; my %data = (); while (<DATA>){ chomp( my $line = $_ ); my @stuff = split /\s+/, $line; ## separate the classes if ( $stuff[0] eq 'B'){ $data{$stuff[0]}{$stuff[1]}{$stuff[2]} = $stuff[3]; } else{ $data{$stuff[0]}{$stuff[1]} = 1; } } print Dumper \%data; for my $group ( keys %{ $data{'G'} } ){ if ( !exists$data{'B'}{ $group } ){ print "Frozen Group \'$group\' is not defined for \'B\' Section.\n +"; } else{ for ( keys %{ $data{'B'}{ $group } } ){ if ( $data{'B'}{ $group }{$_} eq 'ONLINE' ){ print "Group \'$group\' is frozen on host \'$_\'.\n"; } } } } __DATA__ B group1 host1 ONLINE B group1 host2 OFFLINE B group2 host2 ONLINE B group2 host3 OFFLINE B group3 host3 ONLINE B group4 host1 ONLINE B group5 host3 ONLINE G group2 G group3

Gives :

$VAR1 = { 'G' => { 'group2' => 1, 'group3' => 1 }, 'B' => { 'group4' => { 'host1' => 'ONLINE' }, 'group2' => { 'host3' => 'OFFLINE', 'host2' => 'ONLINE' }, 'group1' => { 'host2' => 'OFFLINE', 'host1' => 'ONLINE' }, 'group5' => { 'host3' => 'ONLINE' }, 'group3' => { 'host3' => 'ONLINE' } } }; Group 'group2' is frozen on host 'host2'. Group 'group3' is frozen on host 'host3'.

Probably not the most elegant, but simple usually works best, and maybe i missed what it was you were after, but hopefully this is helpful anyways...

Update : Could also change read in of 'G' data as suggested by moritz and include the next if ($line =~ m/OFFLINE/); as suggested by ccn.

Just a something something...

In reply to Re: Best way to parse my data by BioLion
in thread Best way to parse my data by sierpinski

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.