0

我是新手Perl

<nst:root arg='1' arg2='2' arg3='3'>
   <a>1</a>
   <b>2</b>
</nst:root>

我想要2个变量,例如,

$root = '<nst:root arg='1' arg2='2' arg3='3'>';
$rootClose = '</nst:root>';

我想要一个正则表达式。因为我无法逐行阅读。我的 xml 文件也可以如下所示

<nst:root arg='1' arg2='2' arg3='3'><a>1</a><b>2</b></nst:root>

我不想阅读完整的文件。因为我有 100 个文件,一个文件包含超过 10k 行。

4

1 回答 1

1

尝试这个

open(my $fh,"<your file name");
while(<$fh>){
   $test=$_;
   if ($test =~ /([^>]*)>.*<([^>]*)/g) {
      print qq{$1>  <$2>};
   }
last;
}
于 2013-11-05T10:09:47.543 回答