开发者

Perl XML:Simple read xml pairs and execute something on each of them

I have a XML file which contains the below section:

<cptasks>
 <copy file="file1.txt" to="folder1/folder21" />
 <copy file="file2.txt" to="folder1/folder33" />
 <copy file="file3.txt" to="folder1/folder4" />
 <copy file="file4.txt" to=开发者_如何学Python"folder1/folder1" />
</cptasks>

I need to parse only the file/to pairs in this particular section and run a function on them - i.e.

some_func_name(<file_value>,<to_value>)

How can I do that?

Thank you in advance;


use XML::Simple;
my $cptasks = XMLin(qq~
<cptasks>
<copy file="file1.txt" to="folder1/folder21" />
<copy file="file2.txt" to="folder1/folder33" />
<copy file="file3.txt" to="folder1/folder4" />
<copy file="file4.txt" to="folder1/folder1" />
</cptasks>
~
);


for my $copy (@{$cptasks->{copy}}) {
    some_func_name($copy->{file}, $copy->{to});
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜