http://www.perlmonks.org?node_id=516044

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

Monks,

I'd like to add a second (and possibly others) values to a section of a configuration file. This is known as a multi-part value in Config::Std documentation. The problem is, when the config file is read, there's already one such multi-part value although for the moment it's the only one.

Like this:

[MYSECTION] element: test1
That config file is read and test2 should be added to give the following:

[MYSECTION] element: test1 element: test2

Problem is, when first read, Config::Std returns 'test1' as a scalar. How is it possible to add another value to a scalar unless a modification of the data type is made (i.e. erasing directly the scalar in memory and replacing it by an array) ? Or am I missing something about Config::Std (or Perl in general ;-) that would do this without directly hacking Config::Std's way of representing data ?

...Or when there's only one value, the 'element:' tag should be dropped...

Test code

Save the first snippet above in test.cfg and use the following:

use Config::Std; read_config 'test.cfg' => my %config; print $config{"MYSECTION"}{"element"} . "\n";