in reply to searching all directories with perl

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)
  • Comment on (jeffa) Re: searching all directories with perl

Replies are listed 'Best First'.
Re: (jeffa) Re: searching all directories with perl
by crenz (Priest) on May 05, 2003 at 13:41 UTC

    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.

      Sorry, didn't mean to sound like i was arguing against recursion. Quite the contrary, recursion rules. I simply was pointing out that recursion is not easy, especially when first introduced to it. Remember, telling someone to use File::Find or File::Find::Rule is telling them to use recursion. ;)

      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)
      
        It's more like telling them "you need recursion, but it's hard to get right, so use this module which does the dirty work for you".

        Makeshifts last the longest.