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

File::Find::Rule grep()

by 7stud (Deacon)
on Jan 26, 2013 at 04:41 UTC ( #1015460=perlquestion: print w/replies, xml ) Need Help??
7stud has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

Is it possible to use File::Find::Rule's grep() method to print out the matching line? It seems redundant to find all the files that contain a match, then re-open each file to search for the matching line again to output it. It seems logical to me that File::Find:Rule's grep() would pass the matching line to a subroutine along with the file name, etc. But then again File::Find::Rule quits searching the file after the first matching line, so the search is incomplete anyway.

Replies are listed 'Best First'.
Re: File::Find::Rule grep()
by Anonymous Monk on Jan 26, 2013 at 06:11 UTC

    You tell us? What does the documentation say? And the source?

Re: File::Find::Rule grep()
by 7stud (Deacon) on Jan 26, 2013 at 06:19 UTC
    TIMTOWTDI. I'm using File::Find::Rule instead of File::Find for its globbing capabilities (although File::Find::Rule cannot handle multiple patterns in a glob string).

      TIMTOWTDI. I'm using File::Find::Rule instead of File::Find for its globbing capabilities (although File::Find::Rule cannot handle multiple patterns in a glob string).

      Huh? Sure it can, it uses Text::Glob#glob_to_regex

        $ md tmp $ cd tmp $ echo > asdf $ echo > asdg $ echo > asdh $ echo > bsdf $ echo > bsdg $ echo > bsdh $ echo > csdh $ echo > csda $ echo > csdd $ findrule . -file -name *h asdh bsdh csdh $ findrule . -file -name a* asdf asdg asdh $ findrule . -file -name b* bsdf bsdg bsdh $ findrule . -file -name *h asdh bsdh csdh $ findrule . -file -name {a*,b*,*h} asdf asdg asdh bsdf bsdg bsdh csdh $ cd .. $ findrule tmp -file -name {{a,b}*,*h} tmp/asdf tmp/asdg tmp/asdh tmp/bsdf tmp/bsdg tmp/bsdh tmp/csdh