我试图通过文件解析并收集不同模块中的不匹配类型并生成一个xls。以下是报告模式我需要解析(但实际的报告模式不是简单如下):使用perl和字符串连接解析文件
outsocket ports in design1 not in design2
a
b
Insocket ports in design1 not in design2
g
h
可以有很多花样名(推到模块使用$module
列表)在日志中,但这种格局将(在<>
中的Insocket/outsocket /其他端口不在<>
)
下面是我的核心代码。我遇到了这个代码的问题,并且它不能正常工作(尤其是字符串连接),请帮助我修复这个。
while ($line = <FH>) {
if ($line =~ /Insocket(\s*)ports(\s*)in(\s*)${design1}(\s*)not(\s*)in(\s*)${design2}/) {
$mismatch_type = "type_i_n";
}
elsif ($line =~ /Insocket(\s*)ports(\s*)in(\s*)${design2}(\s*)not(\s*)in(\s*)${design1}/) {
$mismatch_type = "type_i_r";
}
elsif ($line =~ /outsocket(\s*)ports(\s*)in(\s*)${design2}(\s*)not(\s*)in(\s*)${design1}/) {
$mismatch_type = "type_o_n";
}
elsif ($line =~ /outsocket(\s*)ports(\s*)in(\s*)${design1}(\s*)not(\s*)in(\s*)${design2}/) {
$mismatch_type = "type_o_r";
}
$result = $mismatch_type . "_code_ " . $module;
$$result = $$result .$line;
if(!present_in_list ($module,@module_list)) {
push @module_list,$module;
}
push @mismatch_type_list,$mismatch_type;
}#PARSING OF FILE ENDS
#NOW PROCESSING THE RESULTS BASED ON PARSING
foreach $module (@module_list) {
foreach $each_mismatch (@mismatch_type_list) {
$result = $mismatch_type . "_code_ " . $module;
print FH2" $$result,";
}
}
你能否阐述一下代码是如何不工作?该计划的结果如何,您是如何期望它的工作方式不同?由于这是一个不完整的程序,我们对你正在处理什么类型的数据只有非常宽松的想法,所以很难猜测你可能需要什么。 –
你真的应该使用正确的缩进。这将有助于您的节目很多。 – TLP
我试图在解析期间将每个不匹配类型($ mismatch_type)与模块($ module)关联,并最终从我的列表中获取每个模块并显示相关联的行($ line),这些行在解析期间在解析期间连接在一起 – user274739