(WinXP Pro, ActivePerl 5.10.1, and XML-SAX 0.96 used)
MyXML.xml as this
<?xml version="1.0" standalone="yes"?>
<DocumentElement>
<subItem>
<bib>0006</bib>
<name>Stanley Cheruiyot Teimet</name>
<team>肯尼亚</team>
<time>2:17:59</time>
<rank>1</rank>
<comment />
<gender>Male</gender>
<distance>Full</distance>
<year>2010</year>
</subItem>
</DocumentElement>
MyPerl.pl
#!/usr/bin/perl -w
use strict;
use XML::Simple;
use Data::Dumper;
use utf8;
open FILE, ">myXML.txt" or die $!;
my $tree = XMLin('./myXML.xml');
print Dumper($tree);
print FILE "\n";
for (my $i = 0; $i < 1; $i++)
{
print FILE "('$tree->{subItem}->[$i]->{distance}')";
}
close FILE;
Output:
D:\learning\perl\im>mar.pl
$VAR1 = {
'subItem' => {
'distance' => 'Full',
'time' => '2:17:59',
'name' => 'Stanley Cheruiyot Teimet',
'bib' => '0006',
'comment' => {},
'team' => '肯尼亚',
'rank' => '1',
'year' => '2010',
'gender' => 'Male'
}
};
Not an ARRAY reference at D:\learning\perl\im\mar.pl line 41.
I don't know what the Array reference means? The Dumper() works well.But can't print the data to TXT file.
Actually, the sample code ran well days before, Then I remember I upgrade my Komodo Edit from V5. to newest V6.
Today, I just try to improve the script, at the beginning stage, I fixed another error. "Could not find ParserDetails.ini" with google help. (I didn't get the error before!)
But now I get the ARRAY reference error. I already reinstalled my XML-SAX via PPM just now. It still doesn't work.