XML을 파싱 할 때 잘못된 동작을하고 있습니다. 어쨌든 두 개의 루프를 반복해야하는데, 오직 하나만 필요합니다. 여기서 내가 뭘 잘못하고 있니?perl, XML :: Simple을 사용하여 XML 구문 분석하기
먼저 XML 데이터 :
<fishy>
<fish displayName = "Scalar"
description = "the first fish I bought."
/>
<fish displayName = "crystal red"
description = "not really a fish."
/>
</fishy>
그럼 내 펄 코드 :
#!/usr/bin/perl -w
use strict;
use XML::Simple;
use Data::Dumper;
#Read configuration
my $simple = XML::Simple->new();
my $data = $simple->XMLin('test.xml');
print Dumper($data) . "\n";
my @fishes = $data->{fish};
#This is weird.. Why do we have nested arrays?
foreach my $fish (@fishes)
{
foreach my $innerFish (@{$fish})
{
print ("\n" . $innerFish->{displayName} . " is " . $innerFish->{description});
}
print ("\n");
}
그리고 (괜찮습니다) 마지막으로 응답
$VAR1 = {
'fish' => [
{
'description' => 'the first fish I bought.',
'displayName' => 'Scalar'
},
{
'description' => 'not really a fish.',
'displayName' => 'crystal red'
}
]
};
Scalar is the first fish I bought.
crystal red is not really a fish.
없으면 어떻게됩니까? –