Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Should I Make A Module?

by coolmichael (Deacon)
on Mar 16, 2003 at 01:39 UTC ( [id://243396]=perlmeditation: print w/replies, xml ) Need Help??

I have an idea for a new Perl module, that I would call File::Tree. The idea is that you give it a directory, and it returns a structure that represents a directory tree. (Perhaps Directory::Tree?). I would probably base it off File::Find. I haven't put any serious though into this yet. I also have never submitted anything to CPAN.

So, the questions are:
1. Has this been done before? I briefly looked on CPAN, and didn't find anything.
2. Would this be useful for other people? I've already thought of a use for it, but I'm odd that way.

I haven't asked anywhere else yet, as I really like PerlMonks and the remarkably useful answers Here. What do people think? Will this be worth the effort?

--
negativespace.net - all things inbetween.

Replies are listed 'Best First'.
Re: Should I Make A Module?
by Aristotle (Chancellor) on Mar 16, 2003 at 02:02 UTC

    I'm leaning towards it not being worth doing. Something like that is trivial to do with File::Find. Specify the desired data format to produce more closely and someone will likely scribble some code to spit that out in all of a half dozen lines.

    I'm not sure it makes a lot of sense, either.. both the directory structure and the resultant data structure are trees, so you need to write tree-traversal code to do anything with either. Why do whatever it is you need to do while traversing a data structure created by traversing the directory structure, and not do the work right as you're traversing the directory structure, with no intermediate data structure involved?

    On the other hand, if it's the interface of File::Find you don't like - have you looked for an alternative? Tie::Dir lets you treat directories as hashes on the fly, f.ex; it's trivial to write a few lines of wrapper code around it to traverse directory trees. Or to subclass it to return tied hashes when you look at an entry that represents a directory. Or..

    Makeshifts last the longest.

      Tie::Dir doesn't seem to return a recursive data structure, which is what I am looking for. I've run into a few odd circumstances where changing the contents of a directory (creating new files, for example) did strange things to File::Find.

      --
      negativespace.net - all things inbetween.

        As I said, it should be rather simple to subclass it so that it does.

        Makeshifts last the longest.

Re: Should I Make A Module?
by rob_au (Abbot) on Mar 16, 2003 at 05:09 UTC
    Some wise words of wisdom from Elian on whether to build code into a module ... :-)

    1. If you're going to do something more than twice, make it a function
    2. If you're going to use it in more than two programs, make it a module
    3. If doing it even once made your head hurt, throw it in a module
    4. If it has data you don't want to change yourself, make it work from template files
    5. If the code is could be generated from some sort of parameters, use a templating code generator for it
    6. If it feels like a monkey could do it, check the above list to see what you missed

     

    perl -le 'print+unpack("N",pack("B32","00000000000000000000001000111110"))'

Re: Should I Make A Module?
by Ctrl-z (Friar) on Mar 16, 2003 at 11:08 UTC
    make it. I doubt there is much need for it to be a CPAN release, but that shouldn't matter. Writing modules isn't about being on CPAN - its about writing useful, modular pieces of code. And if its damned useful then maybe CPAN is worth the effort.
    But then you get people hassling you about bugs and stuff ;)


    time was, I could move my arms like a bird and...
Re: Should I Make A Module?
by PodMaster (Abbot) on Mar 16, 2003 at 12:45 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://243396]
Approved by Aristotle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-16 13:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found