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
[
{
"oid" : 11365,
"label" : "SystemState.Global.Measurement.AcPowerTotal",
"type" : "i",
"val" : "1667",
"uitext" : "AC Power",
"savetype" : 2,
"factor" : 1.000000,
"unit" : "W",
"portal" : 0,
"AutoZero" : 1,
"fb" : 1
},
{
"oid" : 11650,
"label" : "SystemState.Global.OperatingStatus",
"type" : "i",
"val" : "10",
"uitext" : "operating status",
"savetype" : 2,
"factor" : 1.000000,
"unit" : "",
"portal" : 2,
"AutoZero" : 1,
"fb" : 1
}
]
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
#!/usr/bin/perl use strict; use warnings; use JSON; # Rohdaten in Variable speichern my $json = <<ENDJSON; [ { "oid" : 11365, "label" : "SystemState.Global.Measurement.AcPowerTotal", "type" : "i", "val" : "1667", "uitext" : "AC Power", "savetype" : 2, "factor" : 1.000000, "unit" : "W", "portal" : 0, "AutoZero" : 1, "fb" : 1 }, { "oid" : 11650, "label" : "SystemState.Global.OperatingStatus", "type" : "i", "val" : "10", "uitext" : "operating status", "savetype" : 2, "factor" : 1.000000, "unit" : "", "portal" : 2, "AutoZero" : 1, "fb" : 1 } ] ENDJSON # Daten in Perl-Datenstruktur (hier: Arrayref of Hashrefs) einlesen my $perl_hash_or_arrayref = decode_json $json; # Zugriff auf die Werte: [0] bezeichnet den ersten Datensatz, {val} den daraus zu entnehmenden Wert. print $perl_hash_or_arrayref->[0]->{val};
(label|val): "([^"]+)"
SystemState\.Global\.Measurement\.AcPowerTotal.*?"val" : "([^"]+)"
SystemState\.Global\.Measurement\.AcPowerTotal(?:.*?[\r\n]+)*?"val" : "([^"]+)"
http://rick.measham.id.au/paste/explain.pl?regex=%28%3F%3A.*%3F[\r\n]%2B%29*%3F