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