[bcn-pm] XML::Simple
Arnau Bria
listsarnau a gmail.com
div maig 17 06:16:47 PDT 2013
Hola,
estic intentant parsejar un fitxer xml usant XML::Simple .
estic mirant l'exemple de:
http://search.cpan.org/~grantm/XML-Simple-2.20/lib/XML/Simple.pm (jo tinc la 2.18, però no crec que canvii molt) i
http://docstore.mik.ua/orelly/perl4/cook/ch22_02.htm#perlckbk2-CHP-22-SECT-1 .
el xml :
<?xml version="1.0" ?>
<quota-report time="1368754202">
<global-config>
<quota-global-config>
<reports>
<schedule-pattern>1100000000|every sunday at 11pm</schedule-pattern>
<schedule-dir>/ifs/.isilon/smartquotas/reports</schedule-dir>
<schedule-copies>10</schedule-copies>
<adhoc-dir>/ifs/.isilon/smartquotas/reports</adhoc-dir>
<adhoc-copies>10</adhoc-copies>
</reports>
</quota-global-config>
</global-config>
<global-notify>
</global-notify>
<domains>
<domain type="default-user" snaps="0" lin="0x00000001041778eb">
<path>/ifs/users</path>
<inactive/>
<enforcements default-resource="logical">
</enforcements>
<notifications use="global"/>
</domain>
<domain type="user" snaps="0" lin="0x00000001041778eb" id="0">
<id-name>root</id-name>
<usage resource="physical">1188537212416</usage>
<usage resource="logical">1011751744193</usage>
<usage resource="inodes">761707</usage>
<path>/ifs/users</path>
<inactive/>
<enforcements default-resource="logical">
</enforcements>
<notifications use="global"/>
</domain>
<domain type="user" snaps="0" lin="0x00000001041778eb" id="27">
<inherited/>
<id-name></id-name>
<usage resource="physical">77689344</usage>
<usage resource="logical">65421312</usage>
<usage resource="inodes">19</usage>
<path>/ifs/users</path>
<inactive/>
<enforcements default-resource="logical">
</enforcements>
<notifications use="default"/>
</domain>
[...]
</domains>
</quota-report>
I m'interessa indeificat per id de cada domain. Doncs bé, intento
dir-li que el camp clau (KeyAttr) és domain => id:
my $data = $xml->XMLin("$log_path"."usage-"."$yymmdd".".log", ForceArray => 1, KeyAttr => {'domain' => 'id'});
però passa de mi olímpicament. em mostr lo mateix si ho poso o si no ho
poso:
print Dumper $data;
$VAR1 = {
'global-notify' => {},
'domains' => {
'domain' => [
{
'notifications' => {
'use' => 'global'
},
'enforcements' => {
'default-resource' => 'logical'
},
'inactive' => {},
'path' => '/ifs/users',
'lin' => '0x00000001041778eb',
'type' => 'default-user',
'snaps' => '0'
},
{
'usage' => [
{
'resource' => 'physical',
'content' => '1188537212416'
},
{
'resource' => 'logical',
'content' => '1011751744193'
},
{
'resource' => 'inodes',
'content' => '761707'
}
],
'enforcements' => {
'default-resource' => 'logical'
},
'inactive' => {},
'path' => '/ifs/users',
'lin' => '0x00000001041778eb',
'snaps' => '0',
'notifications' => {
'use' => 'global'
},
'id-name' => 'root',
'type' => 'user',
'id' => '0'
},
{
'usage' => [
{
'resource' => 'physical',
'content' => '77689344'
},
{
'resource' => 'logical',
'content' => '65421312'
},
{
'resource' => 'inodes',
'content' => '19'
}
],
'enforcements' => {
'default-resource' => 'logical'
},
'inactive' => {},
'path' => '/ifs/users',
'lin' => '0x00000001041778eb',
'snaps' => '0',
'inherited' => {},
'notifications' => {
'use' => 'default'
},
'id-name' => {},
'type' => 'user',
'id' => '27'
},
{
'usage' => [
[...]
etc...
algú m'explica on tinc l'error¿ millor utilitzar algun altre mòdul per
parsejar ?
com sempre, gràcies per endavant!
Arnau
Més informació sobre la llista de correu Barcelona-pm