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

Ok, all fair enough and a good challenge to me. However, you keep talking about webservers and the relevant standards or RFCs. In my case, though, what was I supposed to read? The only standards I can think of are things line the Unix or Linux file system hierarchy standard, and that's not relevant to my concern. (At least, if it is, the connection isn't obvious to me.)

I ended up doing this because I was rereading Intermediate Perl, and I kept thinking about the general problem that file system crawling presents: What do you do when (1) you need to drill through a structure, (2) you have no way to predict in advance how far down it goes, and (3) at each branch the items you find may be a simple thing (a file) or a complex thing (a directory containing zero or more directories and zero or more files)? How do you build a map of such a structure in code? Once you have the map, how do you reorganize it for printing? Perhaps you don't want to print it, but you want to extract one piece of information (the byte count) about one of the types of thing in your map (the files). How do you do that most efficiently? The majority of what I do involves files and folders: scanning them for specific types of things, checking their size, updating them, etc. So it's a problem I need to care about.

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? If not, then I would be curious to know what you would recommend I do. But, please, no more webservers. I'm not writing one. I promise.

Replies are listed 'Best First'.
Re^4: Reinvent the wheel!
by chromatic (Archbishop) on Mar 22, 2009 at 03:07 UTC
    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?

      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.