Guest User

Untitled

a guest
Oct 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #TODO: Set keywords, ignorewords somewhere.
  2. #Set reported flag to false\
  3. my $reported = 0;
  4.  
  5. #Loop through the hostfiles Reading contents into variable $hfcontent
  6. foreach my $file (@hostfiles) {
  7. 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";
  8.  
  9. foreach my $hfcline (<$INPUTFH>) {
  10. chomp $hfcline; # Chomp stuff early.
  11. # Loop through keywords checking to see if the keyword matches any content in $hfconent
  12. foreach my $keyword (@keywords) {
  13. #If keyword matches content, start a loop through ignore words
  14. if ($hfcline =~ m/\b$keyword\b/i) { # Might want to ignore case.
  15.  
  16. my $match = 0;
  17. foreach my $igword (@ignorewords) {
  18. print "Keyword: -$keyword- Igword: -$igword-\n";
  19. # FIXME: The following comment does not equal what you're doing in the code on the next line!!!
  20. #If keyword matches a whole ignore word, do nothing
  21. if ($keyword eq $igword ){$match = 1} # Don't use a regex where eq will suffice!!!
  22. print "Match? -$match-\n";
  23. }
  24. if ($match == 1){
  25. # Do nothing yet.
  26. } else {
  27. #Set reported flag to true
  28. $reported = 1;
  29. print "Found word $keyword in log for $file.\n";
  30. print "$hfcline\n";
  31. }
  32. } #end if
  33. } #end foreach $keyword
  34. } #end foreach $hfcline
  35. }
Add Comment
Please, Sign In to add comment