0

我需要比较代表对数变化幅度的列表中的值:

      '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

4

1 回答 1

4

您可以只使用绝对值:

if (abs $condition1_match > abs $condition2_match) {
    push @largest_change, $condition1_match;
}

当然反过来,还有:

elsif (abs $condition1_match < abs $condition2_match) {
    push @largest_change, $condition2_match;
}
于 2013-08-12T18:53:41.437 回答