Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Where to put data that goes with a module?

by Lady_Aleena (Curate)
on Jul 02, 2020 at 04:21 UTC ( #11118780=perlquestion: print w/replies, xml ) Need Help??

Lady_Aleena has asked for the wisdom of the Perl Monks concerning the following question:

I have been documenting my Random modules in a readme for GitHub when I came across some that have external data. Two of them have text files that I open, chomp, and make into an array; nothing special. However, the data for those two are in my general data directory. If I people want to use these modules (and if I ever get them properly written), I will need to put the data closer to them. Now, I just don't know where to put them. (The other modules with external data need hashes made, and that is a bigger problem.)

You might be wondering why I did not put the data directly into the module. It is because two of the lists are over 100 items long and the other two are over 10 with longer strings.

I am also looking to move these Random modules away from using any of my Util modules. My Util modules are messes and for my personal use. (So many PODs to update with their dependencies, hopefully without using any of those Util modules one day.)

I know it may be a matter of taste, but where you would put data files relative to the module that uses them?

My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.8.8 on web host.

No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena
  • Comment on Where to put data that goes with a module?

Replies are listed 'Best First'.
Re: Where to put data that goes with a module?
by swl (Priest) on Jul 02, 2020 at 04:36 UTC
      I have been planning on asking a similar question. In my case, I have an old .pl script which I still occasionally find useful. It requires a large number of sound (.wav) files which it plays by passing their path to "Windows Media Player" with exec. (Because of changes to the Player, it only works reliably on Windows XP. I hope to fix that.) Your suggestion to use build tools to manage the sound files seems like overkill. I have never even attempted to use Makefile.PL and have had only limited success with Build.PL.
      Bill

        Yes, it might well be overkill for many applications. If you have a standalone script that is not going onto CPAN then it's just as easy to add an adjacent data directory to an archive.

        Overkill?
Re: Where to put data that goes with a module?
by tobyink (Canon) on Jul 02, 2020 at 09:08 UTC

    Either use File::ShareDir as swl suggests, or if there's a one-to-one correspondence between modules and data (i.e. your module only needs one data file, and the data file will only be used by that one module) use a __DATA__ section.

      Another option to allow essentially multiple DATA segments is Inline::Files
Re: Where to put data that goes with a module?
by perlfan (Priest) on Jul 02, 2020 at 05:17 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11118780]
Approved by kcott
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2020-08-10 16:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (58 votes). Check out past polls.

    Notices?