This might work for you provided your files are each less than a couple of hundred MB. If that's the case it should a bit quicker than your algorithm above.

#! perl -slw use strict; my( $dir, $glob, $fieldsFile ) = @ARGV; open FIELDS, '<', $fieldsFile or die $!; chomp( my @fields = sort{ length( $b ) <=> length( $a ) } do{ local $/ = "\n"; <FIELDS> } ); close FIELDS; my $re_fields = qr"(@{[ join'|', map{ quotemeta } @fields ]})"; print "@$_" for map { open my $fh, '<:raw', $_ or warn "$_ : $!"; do{ local $/; <$fh> } =~ $re_fields ? [ $1, $_ ] : () } glob "$dir/$glob"; __END__ P:\test>type fields.txt map grep List::Util P:\test>mgrep . *.pl fields.txt List::Util ./200083.pl List::Util ./250802.pl map ./282393.pl map ./306836-trietest.pl map ./308236.pl map ./324513.pl map ./328326.pl map ./330590.pl List::Util ./332124.pl map ./333094.pl map ./333937.pl grep ./334482.pl grep ./335040.pl map ./336125.pl List::Util ./336580.pl ...

You can also supply CON (or maybe /dev/tty on *nix?) in place of the last parameter to have it take the search terms from the keyboard:

P:\test>mgrep . *.pl CON min max ^Z max ./200083.pl max ./250802.pl min ./333502.pl min ./335040.pl min ./336125.pl ...

Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.

In reply to Re: Glob seekpointer by BrowserUk
in thread Glob seekpointer by Shylock

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.