我有两个文本文件,包含品种的柱状数据position- value,排序依据position.
以下是第一个文件(文件A)的示例:
100 1
101 1
102 0
103 2
104 1
...
Run Code Online (Sandbox Code Playgroud)
这是第二个文件(B)的示例:
20 0
21 0
...
100 2
101 1
192 3
193 1
...
Run Code Online (Sandbox Code Playgroud)
而不是将两个文件中的一个读入哈希表,这是由于内存限制而禁止的,我想要做的是以逐步的方式同时遍历两个文件.
这意味着我想通过其中任何一行A或B比较position值进行流式传输.
如果两个位置相等,则我对与该位置相关的值进行计算.
否则,如果位置不相等,我会移动文件A或文件行,B直到位置相等(当我再次执行计算时)或我达到两个文件的EOF.
有没有办法在Perl中执行此操作?
我想知道如何在Perl中实现它:
while ( not the end of the files )
$var1 = read a line from file 1
$var2 = read a line from file 2
# operate on variables
end while
Run Code Online (Sandbox Code Playgroud)
我不知道如何在一个while循环中从两个文件一次读取一行.