- 论坛徽章:
- 0
|
# use module
use XML::Simple;
use Data::Dumper;
use encoding "utf-8";
$xml = new XML::Simple;
$data = $xml->XMLin("beijing.kml",ForceArray=>1);
#print $data;
#print "\n";
if(ref($data) eq "HASH"){
print "it is a hashn";
is_hash($data);
}
sub is_hash{
$data=$_[0];
print $data;
print "\n";
foreach $key(keys %$data){
# print $key;
# print "\n";
print $key."\n";
if(ref(%$data->{$key}) eq "HASH"){
print ":it is a hash2\n";
is_hash($$data->{$key});
}
elsif(ref(%$data->{$key}) eq "ARRAY"){
print "it is a array\n";
is_array(%$data->{$key});
}
elsif(!ref(%$data->{$key})){
print %$data->{$key};
print "\n";
next;
}
}
}
sub is_array{
$data=$_[0];
# print $data;
# print "\n";
for $value (@$data){
if(ref($value) eq "HASH"){
print "it is a hashn";
is_hash($value);
}
elsif(ref($value) eq "ARRAY"){
print "it is a arrayn";
is_array($value);}
elsif(!ref($value)){
print $value;
print "\n";
next;
}
}
}
|
小弟最近解析一个xml文件,但是总是遇到一个错误“Not a HASH reference at readkml.pl line 33.”
由于只会简单调试,我调试了很多遍,也没有搞清楚是怎么回事,哪位大侠有时间帮看一下呢,看是哪里出问题了,先谢谢了。
ps:最好能把调试过程讲解一下,学习学习!
[ 本帖最后由 udbird 于 2009-3-21 09:07 编辑 ] |
|