On Mon, 17 Oct 2005, Beast wrote:

To avoid hardcoding parameter in program, Im trying to make a separate file for config. However its not as simple as key/value which can be easily parse using split.

Why not ? A crude split might fail, but splitting on / = / should work for the format you describe.

But even that wheel doesn't need reinventing. The format your describe isn't all that different from the old Windows .ini format:

    [Marketing]
    [EMAIL PROTECTED]
    [EMAIL PROTECTED]
    subject="Test mkt"
    body="this is a test msg for mkt"

    [Accounting]
    [EMAIL PROTECTED]
    subject="Test acc"
    body="this is a test msg for acct"

There's already a very good module to parse this format. You can write your own, but you might as well just use Config::IniFiles:

    http://search.cpan.org/~gcarls/Config-IniFiles/IniFiles.pm

You could make this as simple or as complex as you want, but a basic script using this module should be very easy to implement.

A CPAN search for 'ini' turns up several similar modules, if this one seems like overkill. Config::Abstract::Ini looks promising, as is Config::IniHash, Config::Tiny, etc. There seem to be dozens...


--
Chris Devers

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to