我需要比较表示日志变化幅度的列表中的值:
'1.3118 2.07985',
'1.18887 0.990066',
'2.63964 2.31757',
'0.828566 1.03155',
'-0.895715 -0.993696',
'1.24353 1.35931',
'1.2916 1.03409',
'-0.747429 -1.18246',
'1.30936 1.20244',
'1.40537 1.27763',
'-1.07762 -0.978337',
'0.755268 0.837232',
'0.919512 1.09517',对于每一行,我希望进行比较,并以最大幅度的变化来存储值。例如,正如我目前拥有的(感谢在这个问题上的帮助,Regex value comparison),这个比较:
if ($condition1_match > $condition2_match) {
push @largest_change, $condition1_match;
}正确地将-0.895715估价为小于-0.993696。然而,我想写一些比较,认为-0.993696是一个比-0.895715更高的折叠变化
发布于 2013-08-12 18:53:41
您可以只使用绝对值:
if (abs $condition1_match > abs $condition2_match) {
push @largest_change, $condition1_match;
}当然,反过来,也是:
elsif (abs $condition1_match < abs $condition2_match) {
push @largest_change, $condition2_match;
}https://stackoverflow.com/questions/18194224
复制相似问题