0

我有一个 XML 文件,其中包含以下部分:

<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>

我只需要解析这个特定部分中的文件/到对并在它们上运行一个函数 - 即

some_func_name(<file_value>,<to_value>)

我怎样才能做到这一点?

先感谢您;

4

1 回答 1

2
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});
}
于 2011-10-13T16:20:35.493 回答