Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1015460]
Approved by Athanasius
help
Chatterbox?
[Corion]: Meh, first round of escalations for me not wanting to fix in production what a project has mismanaged. Now another project, which eats up all the resources until end of this year wants to take that task and put it on my list of things as well.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2017-08-17 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (287 votes). Check out past polls.

    Notices?