1
2
3
4
5
CreationClassName|ElementName|ElementID|OnTimeInMilliseconds
Msvm_ComputerSystem|DevManage|0454C4E6-2C92-41C1-A5FD-D9F145D798D4|1051510957
CreationClassName|DeviceID|LoadPercentage|SystemCreationClassName|ElementID
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|0|Msvm_ComputerSystem|0454C4E6-2C92-41C1-A5FD-D9F145D798D4
1
2
3
4
5
6
7
8
#!/usr/bin/perl -w
use strict;
my ($skalar1, $skalar2);
$skalar1 = "wird gefüllt durch spezielle Abfrage";
$skalar2 = "wird gefüllt durch spezielle Abfrage";
print "$skalar1\n\n$skalar2\n";
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
#!/usr/bin/perl use strict; use warnings; my %elements; # HOH key = ElementId, value = Hashref gemergeter Datensatz # Arrays für die Werte in je einer Zeile my @keys; my @values; # Daten einlesen und HoH befüllen while (my $row = <DATA>) { chomp $row; if ($row =~ m/ElementID/) { # eine Key-Zeile @keys = split(/\|/, $row); @values = (); # neue Key-Zeile, daher Values löschen } elsif ($row =~ /\|/) { # eine Value-Zeile @values = split(/\|/, $row); } else { # eine leere Zeile next; } if (@keys and @values) { die "Ungleiche Anzahl keys und values!" unless scalar @keys == scalar @values; my %entry; for my $i (0..$#keys) { # temporärer Hash, weil Id noch nicht bekannt $entry{$keys[$i]}=$values[$i]; } @keys = (); # Die Arrays leeren für den nächsten Datensatz @values = (); die "Keine ElementID!" unless my $id = $entry{'ElementID'}; for my $key (keys %entry) { # Hashref auffüllen $elements{$id}->{$key}=$entry{$key}; } } } # Ausgabe Ergebnis: for my $elementId (keys %elements) { my %entry = %{$elements{$elementId}}; # Hashref dereferenzieren print join("|", keys %entry) . "\n"; print join("|", values %entry) . "\n"; } __DATA__ CreationClassName|ElementName|ElementID|OnTimeInMilliseconds Msvm_ComputerSystem|DevManage|0454C4E6-2C92-41C1-A5FD-D9F145D798D4|1051510957 CreationClassName|DeviceID|LoadPercentage|SystemCreationClassName|ElementID Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|0|Msvm_ComputerSystem|0454C4E6-2C92-41C1-A5FD-D9F145D798D4
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
__DATA__
CreationClassName|ElementName|ElementID|OnTimeInMilliseconds
Msvm_ComputerSystem|DevManage|0454C4E6-2C92-41C1-A5FD-D9F145D798D4|1051510957
Msvm_ComputerSystem|Goliat4|0AF25718-009E-4D1A-919F-9E0DB2648AEA|1198063907
Msvm_ComputerSystem|CactiEZ|1C75D9AF-C0C3-4D10-B100-E95B7445DF22|1198224173
Msvm_ComputerSystem|Leowsuse3|1D05E39D-EB23-4E9C-BB73-390193B08C7A|630592142
Msvm_ComputerSystem|IPplan|23202E3D-9C0E-418D-9698-4C849901C087|0
Msvm_ComputerSystem|W2k-XP-W2k3|2E134AE0-39B8-43A7-8865-7D6568DD8FFA|1198919452
Msvm_ComputerSystem|Erwin2test|3DD2DE49-6AC5-4B5A-AD3C-0563C7890DFC|0
Msvm_ComputerSystem|Leowsuse|558A0B1E-19DF-48B8-AEEF-1C981109A1BC|1198814872
Msvm_ComputerSystem|Enterprise|6A07D0CA-5CB5-4A77-A385-57D0A0FF1DE9|1198093146
Msvm_ComputerSystem|Nero|6A1E7AF0-D76F-4EA8-BA2A-37C7E32454C4|1195788608
Msvm_ComputerSystem|ADMTL02|9120EA07-BC2D-4D4E-9DAB-DEA283329250|1198604504
Msvm_ComputerSystem|G5Kopie|B055A594-AEC1-4289-AC9D-0BDBFB89ED59|0
Msvm_ComputerSystem|ADMTL04|B760EB72-88B5-4EB7-AFFF-A92DDFC60AC2|1198453806
Msvm_ComputerSystem|observer|B8B57A6C-30A1-49DF-B703-0A1FB4F749D8|1199030741
Msvm_ComputerSystem|Emil|C8A53044-6D54-45BA-ADD0-8FBF58060784|1195700155
Msvm_ComputerSystem|SQELSA|D2B60270-5159-4584-B7A3-6F258CFF16A1|1198965313
Msvm_ComputerSystem|Nhand01|DAC4F1DE-0B96-4451-AA67-4C6C3CEEE4D2|1195943565
Msvm_ComputerSystem|ADMTL01|DBC49355-FF05-4DBE-9BAF-FF40AE0BE3D4|606852144
Msvm_ComputerSystem|Goliat5|E1B1B665-2390-467C-BD70-2F697A973340|679830529
Msvm_ComputerSystem|Test W2k3|F0FB37C2-199E-44DC-9751-5DFE30758305|1198938024
Msvm_ComputerSystem|Acslpz01|FAF99B6C-654D-4423-B952-91D9CAAC2807|1198698286
Msvm_ComputerSystem|ADMTL03|FF53299C-4324-4A48-812F-8C38D264A340|1198564413
CreationClassName|DeviceID|LoadPercentage|SystemCreationClassName|ElementID
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|0|Msvm_ComputerSystem|0454C4E6-2C92-41C1-A5FD-D9F145D798D4
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|1|Msvm_ComputerSystem|0AF25718-009E-4D1A-919F-9E0DB2648AEA
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|2|Msvm_ComputerSystem|1C75D9AF-C0C3-4D10-B100-E95B7445DF22
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|1|Msvm_ComputerSystem|1D05E39D-EB23-4E9C-BB73-390193B08C7A
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|0|Msvm_ComputerSystem|2E134AE0-39B8-43A7-8865-7D6568DD8FFA
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|1|Msvm_ComputerSystem|558A0B1E-19DF-48B8-AEEF-1C981109A1BC
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|15|Msvm_ComputerSystem|6A07D0CA-5CB5-4A77-A385-57D0A0FF1DE9
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|2|Msvm_ComputerSystem|6A1E7AF0-D76F-4EA8-BA2A-37C7E32454C4
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\1|1|Msvm_ComputerSystem|6A1E7AF0-D76F-4EA8-BA2A-37C7E32454C4
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|3|Msvm_ComputerSystem|9120EA07-BC2D-4D4E-9DAB-DEA283329250
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|0|Msvm_ComputerSystem|B760EB72-88B5-4EB7-AFFF-A92DDFC60AC2
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|1|Msvm_ComputerSystem|B8B57A6C-30A1-49DF-B703-0A1FB4F749D8
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|3|Msvm_ComputerSystem|C8A53044-6D54-45BA-ADD0-8FBF58060784
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|0|Msvm_ComputerSystem|D2B60270-5159-4584-B7A3-6F258CFF16A1
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|1|Msvm_ComputerSystem|DAC4F1DE-0B96-4451-AA67-4C6C3CEEE4D2
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|2|Msvm_ComputerSystem|DBC49355-FF05-4DBE-9BAF-FF40AE0BE3D4
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|94|Msvm_ComputerSystem|E1B1B665-2390-467C-BD70-2F697A973340
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\1|92|Msvm_ComputerSystem|E1B1B665-2390-467C-BD70-2F697A973340
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|0|Msvm_ComputerSystem|F0FB37C2-199E-44DC-9751-5DFE30758305
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|7|Msvm_ComputerSystem|FAF99B6C-654D-4423-B952-91D9CAAC2807
Msvm_Processor|Microsoft:b637f346-6a0e-4dec-af52-bd70cb80a21d\0|1|Msvm_ComputerSystem|FF53299C-4324-4A48-812F-8C38D264A340
2011-10-07T14:02:19 choffOh ja das stimmt, da wird eine Zeile weniger ausgegeben, als ich dachte.
1 2 3 4 5 6 7 8 9 10 11
# Ausgabe Ergebnis: my @header = qw(ElementName OnTimeInMilliseconds LoadPercentage); print join("|", @header) . "\n"; for my $elementId (keys %elements) { my @entry = map {defined $elements{$elementId}->{$_} ? $elements{$elementId}->{$_} : ''} @header; print join("|", @entry) . "\n"; }
my @entry = map {$elements{$elementId}->{$_}} @header;
1 2 3 4
my @entry; for my $col (@header) { push @entry, $elements{$elementId}->{$col}; }
defined $elements{$elementId}->{$_} ? $elements{$elementId}->{$_} : ''
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
... my $cmd = "Befehl1"; my $cmmd = "Befehl2"; my $output = `$cmd & $cmmd`;#gleicher Inhalt wie __DATA__ # Daten einlesen und HoH befüllen while (my $row = $output) { #so hatte ich mir das gedacht, anstatt __DATA__ chomp $row; if ($row =~ m/ElementID/) { # eine Key-Zeile @keys = split(/\|/, $row); @values = (); # neue Key-Zeile, daher Values löschen } elsif ($row =~ /\|/) { # eine Value-Zeile @values = split(/\|/, $row); } else { # eine leere Zeile next; } ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/perl use strict; use warnings; my %elements; # HOH key = ElementId, value = Hashref gemergeter Datensatz # Arrays f�r die Werte in je einer Zeile my @keys; my @values; my $row; my $cmd = "Befehl1"; my $cmmd = "Befehl2"; my $output = `$cmd & $cmmd`; print $output;
while (my $row = $output) {
for my $row (split "$/", $output) {