in reply to Best way to parse my data
The interrelationship between your data are not entirely clear to me based on what you've post, so sorry if I'm off point. Once you've used a CSV module to split your data into a list of lists, you could search through the data for matches using either map/grep or nested foreach loops, which tend to be far more legible.
If your issue is ultimately "I have a list of bad groups (G, term 1) that I need to map to a list of hosts (B, term 2) you should probably use a hash of lists keyed on group where your value is the array of hosts in the group. If you don't want to consider OFFLINE hosts, don't add those elements to your lists.
Update: code:
#!/usr/bin/perl use strict; use warnings; my %group_map = (); while (<DATA>) { my @list = split; if ($list[0] =~ /B/) { my ($group,$host,$online) = @list[1..3]; next if $online =~ /OFFLINE/; # filter "OFFLINE" push @{$group_map{$group}}, $host; next; } if ($list[0] =~ /G/) { my $group = $list[1]; foreach my $host (@{$group_map{$group}}) { print "$group is frozen on $host\n"; } next; } } __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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Best way to parse my data
by toolic (Bishop) on Sep 30, 2009 at 16:59 UTC | |
|
Re^2: Best way to parse my data
by sierpinski (Chaplain) on Sep 30, 2009 at 16:56 UTC | |
by kennethk (Abbot) on Sep 30, 2009 at 16:59 UTC | |
by sierpinski (Chaplain) on Sep 30, 2009 at 17:12 UTC |