Thread Welches Config:: Modul am sinnvollsten?: Konfigurationen lesen/schreiben (19 answers)
Opened by GwenDragon at 2007-03-15 17:41

bloonix
 2007-03-15 17:50
#75067 #75067
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Hallo Gwen,

CPAN:Config::Properties ist ein tolles Modul. Ich nutze es derzeit als einziges Config::* Modul.

Was mir an dem Modul so gut gefällt ist zum Beispiel:

Config file
Code: (dl )
1
2
3
key1.key2.key3 = value1
key1.key3.key4 = value2
key2.key4.key6 = value3


Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use strict;
use warnings;
use Config::Properties;
use Data::Dumper;

my $file = 'test.cfg';

open my $fh, '<', $file or die "Unable to open $file ($!)";
my $properties = Config::Properties->new();
$properties->load($fh);
my $config = $properties->splitToTree(qr/\./);
close $fh;

print Dumper($config);


Output

$VAR1 = {
         'key2' => {
                     'key4' => {
                                 'key6' => 'value3'
                               }
                   },
         'key1' => {
                     'key2' => {
                                 'key3' => 'value1'
                               },
                     'key3' => {
                                 'key4' => 'value2'
                               }
                   }
       };


Gruss,
opi\n\n

<!--EDIT|opi|1173973890-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread Welches Config:: Modul am sinnvollsten?: Konfigurationen lesen/schreiben