Quoteperl 5, version 20, subversion 2 (v5.20.2) built for MSWin32-x86-multi-thread-64int
Quoteperl 5, version 16, subversion 2 (v5.16.3) built for MSWin32-x64-multi-thread-64int
2015-12-10T15:47:05 LinuxerZu wenig Information. Keine Antwort möglich.
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
#!/usr/local/bin/perl use Modern::Perl; use autodie; use XML::Twig; use File::Basename; use Data::Dumper; my $arg_file = shift @ARGV; my $default_file = 'default_sysvalue.xml'; my @files = glob('*.xml'); @files = grep { $_ ne $arg_file } @files if defined $arg_file; my $result_file = 'DATA.csv'; sub timestamp { my $i; return sprintf "%04d%02d%02d %02d:%02d:%02d", map {$_ + (1900,1,0,0,0,0)[$i++]} reverse ((localtime)[0..5]); } my $sep_char = ";"; my $uuid = '3F56E1C5-D6B9-1014-9A88-CDB8776B8231'; my %defaults; $defaults{$uuid} = []; my $default_twig = XML::Twig->new( twig_handlers => { 'Parameter' => sub { my $cat_id = @{$defaults{$uuid}}[-1]; my $name = $_->{'att'}->{'name'}; my $target = $_->first_child('Target'); if ($name ne "" ) { if ($target) { $name = $target->{'att'}->{'instance'}. '--' . $name ; } push @{$defaults{$cat_id}{$uuid}}, $name; $defaults{$cat_id}{$name} = $_->{'att'}->{'value'} // 'fault';}}}, start_tag_handlers => { 'Catalog' => sub { my $cat_id = $_->{'att'}->{'id'}; push @{$defaults{$uuid}}, $cat_id; $defaults{$cat_id}{$uuid} = [];} }); $default_twig->parsefile($default_file); open my $fhout, ">", $result_file; print $fhout timestamp(), "\n"; print $fhout ((split(/_/, basename($default_file)))[0]); foreach my $cat_id (@{$defaults{$uuid}}) { foreach my $name (@{$defaults{$cat_id}{$uuid}}) { print $fhout $sep_char, $name; } } print $fhout "\n"; print $fhout "default"; foreach my $cat_id (@{$defaults{$uuid}}) { foreach my $name (@{$defaults{$cat_id}{$uuid}}) { print $fhout $sep_char, $defaults{$cat_id}{$name}; } } print $fhout "\n"; foreach my $file (@files) { my %datas; $datas{$uuid} = []; my $datas_twig = XML::Twig->new( twig_handlers => { 'Parameter' => sub { my $cat_id = @{$datas{$uuid}}[-1]; my $name = $_->{'att'}->{'name'}; my $target = $_->first_child('Target'); if ($name ne "" ) { if ($target) { $name = $target->{'att'}->{'instance'}. '--' . $name ; } push @{$datas{$cat_id}{$uuid}}, $name; $datas{$cat_id}{$name} = $_->{'att'}->{'value'} // 'fault';}}}, start_tag_handlers => { 'Catalog' => sub { my $cat_id = $_->{'att'}->{'id'}; push @{$datas{$uuid}}, $cat_id; $datas{$cat_id}{$uuid} = [];} }); $datas_twig->parsefile($file); print $fhout (split(/_/, ((split(/\./, basename($file)))[0])))[0]; foreach my $cat_id (@{$defaults{$uuid}}) { foreach my $name (@{$defaults{$cat_id}{$uuid}}) { print $fhout $sep_char, ($datas{$cat_id}{$name} // 'missing'); } } print $fhout "\n"; } close $fhout;