Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #TODO: Set keywords, ignorewords somewhere.
- #Set reported flag to false\
- my $reported = 0;
- #Loop through the hostfiles Reading contents into variable $hfcontent
- foreach my $file (@hostfiles) {
- open( $INPUTFH, "<", $file); #I prefer $filehandle but it's personal pref. Always state the open type explicitly, I prefer the 3-param invocation, or else you have to do open FH, "<$fname";
- foreach my $hfcline (<$INPUTFH>) {
- chomp $hfcline; # Chomp stuff early.
- # Loop through keywords checking to see if the keyword matches any content in $hfconent
- foreach my $keyword (@keywords) {
- #If keyword matches content, start a loop through ignore words
- if ($hfcline =~ m/\b$keyword\b/i) { # Might want to ignore case.
- my $match = 0;
- foreach my $igword (@ignorewords) {
- print "Keyword: -$keyword- Igword: -$igword-\n";
- # FIXME: The following comment does not equal what you're doing in the code on the next line!!!
- #If keyword matches a whole ignore word, do nothing
- if ($keyword eq $igword ){$match = 1} # Don't use a regex where eq will suffice!!!
- print "Match? -$match-\n";
- }
- if ($match == 1){
- # Do nothing yet.
- } else {
- #Set reported flag to true
- $reported = 1;
- print "Found word $keyword in log for $file.\n";
- print "$hfcline\n";
- }
- } #end if
- } #end foreach $keyword
- } #end foreach $hfcline
- }
Add Comment
Please, Sign In to add comment