my @matching_file = File::Find::Rule
->file()
->name( '*.html' )
->grep( qr/\Q$keyword/ )
->in( "." );
Makeshifts last the longest. | [reply] [d/l] |
Aristotle++ on the quick draw! ;) He is dead on.
File::Find and File::Find::Rule
are the tools to use. The problem with
processing all directories and not just the first one needs
a solution called recursion. Recursion is a fairly
advanced computer science technique that involves having
a subroutine call itself. It can get quite tricky. Couple
recursion with symbolic links and you can find your code getting 'stuck' in an infinite loop. Doing
a simple Super Search on 'directory recurs' yielded a lot
of good nodes, such as the famous How do I recursively process files through directories by the
infamous Paco. There are more, read them. :)
Also, there is a good tutorial on File::Find
here at the monastery, and last year's Advent Calendar featured File::Find::Rule for the
11th day. Best of luck to you! :)
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
| [reply] |
Recursion is a fairly advanced computer science technique that involves having a subroutine call itself. It can get quite tricky.
Huh? Fairly advanced? That's one of the first things you hear about in CS, I think. While I totally agree with the advice to use File::Find, I don't see a reason for advocacy against recursion in general. It can be a very elegant solution to solve problems in a simple and understandable way.
Of course recursion, if used wrongly, can lead to endless loops etc. But that's not an argument against using it. It's an argument in favour of learning to use recursion the right way.
| [reply] |
| [reply] |