note
Jenda
<p>To add to the list of options...</p>
<code>
use strict;
use XML::Rules;
use Data::Dumper qw(Dumper);
my $parser = XML::Rules->new(
stripspaces => 15,
rules => {
'name,value' => 'content',
statistic => sub { return '%' . $_[1]->{type} => { $_[1]->{name} => $_[1]->{value}} },
resourceGroup => 'no content array',
statRecord => sub {
#print Dumper($_[1]);
foreach my $group (@{$_[1]->{resourceGroup}}) {
print "$_[1]->{time}|$group->{name}|$group->{Lifetime}{LCONNFAIL}|$group->{Lifetime}{LLOSTCONN}|$group->{Lifetime}{LIDLETIMEOUT}|$group->{Startup}{SIPADDR}|$group->{Startup}{SIPPORT}\n";
}
return;
}
}
);
print "time|resourceGroup name|LCONNFAIL|LLOSTCONN|LIDLETIMEOUT|SIPADDR|SIPPORT\n";
$parser->parse(\*DATA);
__DATA__
<?xml version="1.0" encoding="UTF-8"?>
<ctgStatistics xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ctgstatslog.xsd">
<statRecord type="interval" length="60" time="2019-07-16T08:23:59">
<resourceGroup name="CSCS1SVGM1">
<statistic type="Startup">
...
</code>
or
<code>
use strict;
use XML::Rules;
use Data::Dumper qw(Dumper);
my $parser = XML::Rules->new(
stripspaces => 15,
rules => {
'name,value' => 'content',
statistic => sub { return $_[1]->{name} => $_[1]->{value} },
resourceGroup => 'no content array',
statRecord => sub {
#print Dumper($_[1]);
foreach my $group (@{$_[1]->{resourceGroup}}) {
print "$_[1]->{time}|$group->{name}|$group->{LCONNFAIL}|$group->{LLOSTCONN}|$group->{LIDLETIMEOUT}|$group->{SIPADDR}|$group->{SIPPORT}\n";
}
return;
}
}
);
print "time|resourceGroup name|LCONNFAIL|LLOSTCONN|LIDLETIMEOUT|SIPADDR|SIPPORT\n";
$parser->parse(\*DATA);
__DATA__
<?xml version="1.0" encoding="UTF-8"?>
<ctgStatistics xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ctgstatslog.xsd">
<statRecord type="interval" length="60" time="2019-07-16T08:23:59">
<resourceGroup name="CSCS1SVGM1">
<statistic type="Startup">
...
</code>
<p>The first version preserves the statistics type in the data provided to the handler of the statRecord tag, the second assumes there will be no duplicate names of statistics and ignores the types.</p>
<p>There's only the data from one <statRecord> in memory at any time.</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-105128">
<p>Jenda<br>
<b>Enoch was right!</b><br/>
Enjoy the last years of Rome.
</p>
</div></div>
11103530
11103530