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

Hello, I currently maintain a module which parses logfiles according to different formats. The formats are stored in a big hash in the main .pm file. I was thinking to move the configuration out of there and in a YAML file (or other serialization format, I don't mind) and then have the module load it at initialization. Ideally, I would also wnt people to be able to add and delete entries there. Is there some sort of "Good practice" for things like this? thanks Spiros

Replies are listed 'Best First'.
Re: module with external file
by bellaire (Hermit) on Dec 12, 2009 at 12:59 UTC
    There is no single best practice. Different people have different preferences and practices, including (and not limited to):
    • Using plain Perl data structures in a separate "Config" module
    • INI-style config files via e.g. Config::IniFiles
    • YAML
    • XML
    • JSON
    Here's a couple of other useful nodes where discussion has taken place:
      Hello, thanks for the reply - I apologise if my question was not clear. I know how to create and manipulate config files in general. What I am after is any good practices of having a distribution with a config file. Is it as simple as creating a .conf and having it in the same directory? Does CPAN installation support this etc thanks Spiros
        Oh, in that case you can look at something like Module::Install::Share for handling the installation of non-code files with your distribution.
Re: module with external file
by BrowserUk (Patriarch) on Dec 12, 2009 at 17:12 UTC

    You could place the info in the .pm file after the __DATA__ token and read it using <Your::Package::DATA>.

    This has the nice side effect of keeping everything together, with the downside that any local updates would be overwritten by a later install.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: module with external file
by Anonymous Monk on Dec 12, 2009 at 13:29 UTC
Re: module with external file
by hangon (Deacon) on Dec 13, 2009 at 08:59 UTC