split就可以完成这项工作。缓冲线以顺序比较它们。
use strict;use warnings;my @line;while (<>) { push @line, $_; # add line to buffer next if @line < 2; # skip unless buffer is full print proc(@line), "n"; # process and print shift @line; # remove used line }sub proc { my @a = split ' ', shift; # line 1 my @b = split ' ', shift; # line 2 my $x = ($a[6]-$b[6]); # calculate the diffs my $y = ($a[7]-$b[7]); my $z = ($a[8]-$b[8]); my $dist = sprintf "%.1f", # format the number sqrt($x**2+$y**2+$z**2); # do the calculation return "$a[3]-$b[3]t$dist"; # return the string for printing}
输出(带有示例数据):
GLN-HIS 3.8HIS-ASN 3.8ASN-GLU 3.9GLU-VAL 3.8
如果您的数据以制表符分隔,则可以分割
/t/而不是
' '。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)