我有一段像下面这样的 xml 代码我会读到这个并用换行符分割它
<head>
<name>states.opml</name>
<Created>Tue, 15 Mar 2005 16:35:45 GMT</Created>
<Modified>Thu, 14 Jul 2005 23:41:05 GMT</Modified>
<owner>Dave Winer</owner>
<Email>dave@scripting.com</Email>
<expansion>1, 6, 13, 16, 18, 20</expansion>
<vertScrollState>1</vertScrollState>
<windowTop>106</windowTop>
<windowLeft>106</windowLeft>
<windowBottom>558</windowBottom>
<windowRight>479</windowRight>
</head>
我的 perl 代码:
my $xml=<STDIN>;
my @head=split(/\n/,$xml);
print length(@head);
#output is 1...split is not working at all
我想要的是:我想要的是这样的字符串数组:
@head={<head>,
<name>states.opml</name>,
<Created>Tue, 15 Mar 2005 16:35:45 GMT</Created>,
<Modified>Thu, 14 Jul 2005 23:41:05 GMT</Modified>,
<owner>Dave Winer</owner>,
<Email>dave@scripting.com</Email>,
<expansion>1, 6, 13, 16, 18, 20</expansion>,
<vertScrollState>1</vertScrollState>,
<windowTop>106</windowTop>,
<windowLeft>106</windowLeft>,
<windowBottom>558</windowBottom>,
<windowRight>479</windowRight>,
</head>}
有人可以帮忙吗?我知道 XML::XMLin,但不允许使用它。
谢谢!