This code print $OUT "$filename\n" if grep{/DATAmessage.*3\.0/}<$in>; is slow because it continues to read the file even after it has found the first occurrence of the regex match (it actually counts the number of occurrences in the file). To use hippo's idea: add use List::Util qw(any); at the top. And change code to print $OUT "$filename\n" if any{/DATAmessage.*3\.0/}<$in>;.

the "any" routine is written in C. The Perl equivalent is like this:

while (<$in>) { if (/DATAmessage.*3\.0/) { print $OUT "$filename\n"; last; #no need to look anymore! } }
If whatever you are looking for usually appears near the beginning of the file, performance gain will be substantial.

update:
Another place to use a List::Util function:

{ my %unique; print $OUT sort grep { ! $unique{ $_ }++ } <$IN>; } ##### again use List::Util to speed up Perl implementation... #### use List::Util qw(any uniq); print $OUT sort uniq <$IN>;
I suppose that depending upon the data, it could be that reversing the order, i.e., sorting and then filtering out uniq lines would be faster? Don't know. But if speed is needed, I would also benchmark that approach. Also, instead of building a hash table, try: "print line unless its a repeat of previous line". Results probably depend upon what typical data actually looks like. For example:
my $prev = ""; foreach (sort <$IN>) { print unless $_ eq $prev; $prev = $_; }

In reply to Re^3: Using system (); with Strawberry Perl by Marshall
in thread Using system (); with Strawberry Perl by hadrons

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.