Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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.

Comment on File::Find::Rule grep()
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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-09-01 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (299 votes), past polls