Which grep is on your mind, the internal perl function grep or the command line utility grep? Generally there is (especially in Perl) more than one way to do things, though some are better than others in a given situation.

You also seemed to imply that both data files are huge. Does that mean you are searching for thousands or millions of values in file 2 ?

If that were the case, a lot would depend on the characteristics of the data. If it is only single words you could create a hash (stored on disc) of the words in file 1 and check every word in file 2 for existance in the hash. If you are looking for whole lines instead, you could sort file 2 and your seach list and work from the beginning in both lists

If the list you are looking for is small on the other hand you could concatenate all search strings with '|' and use that string as search pattern, somewhat like this (untested):

my $searchstring= '\Q' . join('\E|\Q',@output). '\E'; while (my $line=<FILE2>) { if ($line=~/$searchstring/) { print $line; } }

\Q and \E make sure your search strings have any regex special characters like '|' escaped.

Other observations: ++ for your use of warnings and strict. But you also should indent correctly. Makes your code much more readable

And concerning your second posting. Please edit and use code tags for your data examples too


In reply to Re: General program and related problems by jethro
in thread General program and related problems by micky744monk

Title:
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, 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:
    & &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.