Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Should I Make A Module?

by coolmichael (Deacon)
on Mar 16, 2003 at 01:39 UTC ( #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?

-- - 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.

      -- - 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://243396]
Approved by Aristotle
[Discipulus]: it is for my father: it is impossible to tell him to learn a newer OS
[Lady_Aleena]: To tell him or teach him?
Discipulus anyway xp is still the best lowend game machine
[Discipulus]: both: everyting must be identical in the new v-machine
[Lady_Aleena]: So putting a nice DE or WM up on a Linux machine is not an option?
[Discipulus]: i need some converter to have directly an OVF format directly: at the moment i'm trying with vmware converter standalone
[Lady_Aleena]: I don't know what to tell you. I can barely get my Linux machine to do things I want.
[Discipulus]: if DE or WM means desktop env and win manager.. no, not an option
[Lady_Aleena]: That's what they mean, at least to me. 8)
[Discipulus]: in the first attempt i failed, with an not usable v-machine.. ;=)

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2017-05-22 18:40 GMT
Find Nodes?
    Voting Booth?