1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
use 5.012; use warnings; my %records; do { my $name; my $record; while (my $line = <DATA>) { chomp $line; if (defined $name) { if (length $line > 0) { # Data line my ($k, $v) = split /\s*=\s*/, $line, 2; $record->{$k} = $v; } else { # Reached end of record $records{$name} = $record; $name = undef; $record = undef; } } else { if (length $line > 0) { # Beginning of record $name = $line; $record = {}; } else { # Additional empty line between records } } } if (defined $name) { $records{$name} = $record; } }; use Data::Dumper; print Dumper \%records; __DATA__ h cool = ja schön = nein d cool = nein schön = ja b cool = nein schön = nein
1
2
3
4
5
6
7
8
9
10
11
[h]
cool = ja
schön = nein
[d]
cool = nein
schön = ja
[b]
cool = nein
schön = nein
1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/perl use warnings; use strict; use Config::Simple; use Data::Dumper; my %Config; Config::Simple->import_from('config.ini', \%Config); print Dumper(\%Config);
1
2
3
4
5
6
7
8
$VAR1 = {
'h.schön' => 'nein',
'd.schön' => 'ja',
'h.cool' => 'ja',
'b.cool' => 'nein',
'b.schön' => 'nein',
'd.cool' => 'nein'
};
my @datasets = split m{\n\n}, $datenwust;