in reply to Best way to parse my data

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...

Replies are listed 'Best First'.
Re^2: Best way to parse my data
by sierpinski (Chaplain) on Sep 30, 2009 at 16:48 UTC
    That looks to be exactly what I need... If anyone was interested, here is what I've tried:

    # $frozen_cmd contains the command that provides the data I posted or +iginally in the 'G' section $ssh->send("$frozen_cmd"); my %frozen; while ( defined ($line = $ssh->read_line()) ) { $frozen{$line} = ''; } my $key; foreach $key (%frozen) { # $tmpcmd1 contains the command to look for just the specific entry of + "B" for that one group $ssh->send($tmpcmd1); my $frozhost = $ssh->read_line(); $frozen{$key} = $frozhost; }
    I'll try your method out and see if that does the trick, but it looks like you got it.. Thanks so much!
    /\ Sierpinski