我需要解析一个xml 文件,我在 perl 僧侣网站上找到了这段代码,我无法理解代码,我需要的是能够访问哈希数组元素。
use Data::Dumper;
use XML::Rules;
my $parser = XML::Rules->new(
stripspaces => 7,
rules => {
substrate => sub { 'substrate' => $_[1]->{id}},
product => sub { '@products' => $_[1]->{id}},
reaction => sub {
my %reactions;
foreach (split / /, $_[1]->{name}) {
$reactions{$_} = { substrate => $_[1]->{substrate}, products => $_[1]->{products}};
}
return '%reactions' => \%reactions;
},
graphics => '',
entry => sub {
my @reactions = split ' ', (delete $_[1]->{reaction});
$_[1]->{reactions} = \@reactions if @reactions;
return '%entries' => {$_[1]->{id} => $_[1]}
},
pathway => 'pass'
});
print Dumper ($parser->parsefile('ko00010.xml'));