Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
You may want to put the list of keywords in an array to create a regex and then iterate through the lines of each file and test for the keywords. This is a little sloppy but I hope you get the idea:
my @KEYWORDS = qw(hello there you gurus); # create the regex my $string = ''; foreach (@KEYWORDS){ $string .= "$_||"; } $string =~ s/\|\|$//; # open the log file open(LOGFILE,$logfilename)||die"Cannot open $logfilename\n$!\n" # let's go through the files.... foreach (@files) { $filename = $_; open(FILE,$filename)||die"Cannot open $filename\n$!\n"; #check if a keyword is in the line while(<FILE>){ if (/$string/i){ print LOGFILE "Keyword found in $filename\n"; } } }


In reply to Re: Search Algorithm by mrmick
in thread Search Algorithm by tenfourty

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (3)
    As of 2018-05-28 06:10 GMT
    Find Nodes?
      Voting Booth?