Leser: 19
1
2
3
4
5
6
7
8
9
10
11
12
13
{
a => {
a => {
a => 'A',
b => 'B',
},
},
c => {
b => 'E',
a => 'D',
},
b => 'C',
}
1 2 3 4 5 6 7 8 9 10 11 12 13
my $new = {}; tree($new, $_, $hash{$_}) for keys %hash; sub tree { my ($target, $key, $val) = @_; my ($char, $rest) = split /\./, $key, 2; unless (defined $rest) { $target->{$char} = $val; return; } $target->{$char} ||= {}; tree($target->{$char}, $rest, $val); }
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
sub get_element_by_name($$) { my ($conf,$name)=@_; return undef unless(is_valid($conf,'name',$name)); my $system=$conf->{system}; my $data=$conf->{data}->{$system}; return $data->{elements}->{$name} } sub get_element_namespace($$) { my ($conf,$element)=@_; return undef unless(is_valid($conf,'element',$element)); my $system=$conf->{system}; my $data=$conf->{data}->{$system}; return $data->{namespaces}->{$element->{namespace}}; } sub get_namespace_default($$) { my ($conf,$namespace)=@_; return undef unless(is_valid($conf,'namespace',$namespace)); my $system=$conf->{system}; my $data=$conf->{data}->{$system}; my $default=$data->{default}; my $name=$data->{namespaces}->{$namespace}->{$default}; return $data->{elements}->{$name}; }
$namespace->{alternative}->{namespaces}->{'namespacex'}->{systems}->{'systemy'}->{name}
$element->{description}->{lang}->{'de'}->{encoding}->{defalult}->{fallback}->{type}->{'UTF'}->{subtype}='8';
1 2 3 4 5
my $fs=$system->{$element->{system}}->{filesystem}; my $sep=$fs->{separator}; my $dname=$fs->{data}->{file}->{name}; my $dfile=$fs->{file}->{$dname}->{absolue}->{path}->{separator}->{$sep} $dfile=$fs->{file}->{$dname}->{is}->{linked}->{to}->{file}->{absolute}->{path}->{separator}->{$sep} if($fs->{file}->{$dname}->{is}->{linked}->{to}->{file}->{absolute}->{path}->{separator}->{$sep});
system SystemX filesystem file Daten1 is linked to file absolute path separator / = mounts/mounta/data.dat
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
sub load { my $file=shift; defined($file) or die(qq(No file defined!\n)); -f $file or die(qq(ERROR: File "$file" not defined or not exists\n)); open(my $fh, '<', $file) or die(qq(ERROR: Can't open File "$file" $!\n)); my $ret={}; my $lastkey; while(my $line=<$fh>) { chomp($line); next if($line=~/^\s*#/o || $line=~/^\s*$/o); if(my ($key,$value)=$line=~/^\s*([^=]+?)\s*=\s*(.*?)(?:#.*)?\s*$/o) { $ret->{$key}=$value // ''; $lastkey=$key; } elsif($lastkey) { $ret->{$lastkey}.="\n$line"; } } close($fh); return $ret; } sub parse { my $hash=shift; my $sep=shift // '.'; return {} unless($hash && ref($hash) eq 'HASH'); my $ret={}; KEYLOOP: for my $k (keys(%$hash)) { my $ref=\$ret; my @kk=(); for my $n (split(/\Q$sep\E/,$k)) { push(@kk,$n); $ref=\$$ref->{$n}; next KEYLOOP if($$ref && !ref($$ref)) } $$ref=$hash->{$k}; } return $ret; }