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.
In reply to Re: Best way to parse my data
by BioLion
in thread Best way to parse my data
by sierpinski
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |