Perl 脚本读取 property.xml 并创建 install.properties 文件
如何读取多行并拆分 keyName 和 keyValue
#!/usr/bin/perl
use strict;
use warnings;
open my $fh, '<', "property.xml" or die "property.xml: $!";
open(CTS,">install.properties") or die $!;
while ( my $line = <$fh> ) {
if ($line =~ m/\<entry.*\<\/entry\>$/i ){ # how to read multiple line
my ($keyName, $keyValue) = split(//, $line); # how to split
print CTS $keyName = $keyValue;
}
}
属性.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="TYPE">
Rel
</entry>
<!-- tst -->
<entry key="LOCATION">
C:/Rel-LOCATION
</entry>
<entry key="HOST">
localhost
</entry>
</properties>
安装.properties
TYPE = Rel
LOCATION = C:/Rel-LOCATION
HOST = localhost