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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.