#! /usr/bin/perl -w
$input = shift @ARGV;
$output = shift @ARGV;
open FHINPUT,"$input";
open FHOUTPUT,">$output";
while(<FHINPUT>)
{
@nums = split(" ",$_);
$res = ".config_T".hex(shift(@nums));
$n = hex(shift(@nums));
$count = hex(shift(@nums));
if ( $n ) {
$res = "$res _$n = {";
} else {
$res = "$res = {";
}
for $item (@nums)
{
$res = $res.hex($item).",";
}
$res =~ s/,$/},/;
print FHOUTPUT "$res\n";
}
close FHINPUT;
close FHOUTPUT;
还有两个问题:1、我想用编号区分一下(编号仅含0的T后不变、编号非0区分)就是形如如下输出:
.config_T103_0 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0},
.config_T103_1 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0},
.config_T104 = {1,2,120,15,12,2,2,120,15,12,2},
.config_T105 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
我自己加了句代码不能实现编号非0时的0号输出
2、运行脚本后T103后面会有空格(本意是不要有空格),如果程序写成$res = "$res_$n = {"; 又会报错;
上面到程序输出结果会变成
.config_T103 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0},
.config_T103 _1 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0},
.config_T104 = {1,2,120,15,12,2,2,120,15,12,2},
.config_T105 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
求指导
@自由de王国