in reply to Re^3: Reinvent the wheel!
in thread Reinvent the wheel!

In my case, though, what was I supposed to read?

Fair enough. In your case, a good POSIX or Unix book which describes how filesystems work. In particular, some of the grottiest code in File::Find detects such weirdnesses as recursive symbolic and hard links that can turn a nice tree structure into a complex graph with cyclic relationships. That's a common enough situation that will not be obvious to most autodidacts trying to deal with this sort of problem.

How about dealing with orphaned symlinks? Non-regular files? Mount points? Overlays?

It's also a very common problem in graph traversal, of which "How do I find files under this directory according to some pattern?" is a refinement.

I kept thinking about the general problem that file system crawling presents....

Of course. This is a good example and learning opportunity. By no means do I mean to suggest otherwise. Yet a robust solution to the problem is far more complex than you might suspect.

Perhaps I'm reacting poorly to the phrase "reinventing the wheel", which connotes to me that you've examined the existing solutions and found them lacking in some means. (In my experience, the people who claim that they have really haven't, not in any detail.) Perhaps I've misunderstood you.

If I understand you correctly, you're saying that my time would have been better spent reading through the code in File::Find. Is that your point?

In specific, I can't recommend reading that code. It's not great. It does, however, address a lot of problems that occur in the real world that a robust filesystem walker does need to address. What's a good way of agreeing to the general question but backing off from the specifics?

Replies are listed 'Best First'.
Re^5: Reinvent the wheel!
by telemachus (Friar) on Mar 22, 2009 at 04:12 UTC

    Perhaps I'm reacting poorly to the phrase "reinventing the wheel", which connotes to me that you've examined the existing solutions and found them lacking in some means. (In my experience, the people who claim that they have really haven't, not in any detail.) Perhaps I've misunderstood you.

    I didn't mean "reinventing the wheel" that way, but given how loaded the phrase is, I suppose I knew I was asking for trouble. To clarify: I never intended to replace File::Find. I wanted to see if I understood some of what I had learned from Intermediate Perl and the first chapter of Higher Order Perl, and the way I tested my understanding was by selecting a subset of File::Find's functionality and trying to reproduce it - not because I thought I could do better, but as an exercise. My original post (far) overstated how well I succeeded at even that limited task, and I see that the title is misleading. But I'm glad that I provoked strong responses. I was curious to hear what other, more experienced monks thought of this as a learning exercise. As I've said a few times, I'm completely isolated as far as programming goes, so all the feedback has been very helpful.

    In any case, I appreciate your responses; the comments about 'prior art' are especially helpful. Although I use plenty of modules for their functionality, I haven't made enough use of the actual source code as a teaching tool.