I have a log file that I need to divide into 'good' and 'bad' arrays based on whether or not the line contains a website listed in another array. In the snippet below, I am just trying to get the lines that match one of the sites to go in the 'bad' array, but its returning everything. The $sites file just contains a list of websites, one per line (www.yahoo.com, etc) and the $log file contains all kinds of info per line, including a website.
open ($sites_fh, '<', $sites)or die "Can't open '$sites': $!";
chomp(@sites = <$sites_fh>);
open ($log_fh, '<', $log) or die "Can't open '$log': $!";
while (<$log_fh>) {
foreach my $site (@sites) {
push @bad_log, $_ if ($_ =~ /$site/);
}
}
print "@bad_log\n"; #currently returns entire $log
any help is appreciated
$sites sample:
www.yahoo.com
www.google.com
www.comcast.com
$log sample:
X456 TV-yes DB-no 123.12.23.45 dealio3 www.google.com-------- FX-yes d
+53 Y-03
X123 TV-yes DB-yes 34.154.43.21 dealio1 www.ask.com-------- FX-no d01
+Y-03
X412 TV-no DB-no 192.365.25.23 rayovac2 www.microsoft.com--- FX-yes d1
+3 Y-07
with the samples above, only the first line of $log should end up in @bad_log, and the others would go to @good_log, once thats created