私のコメントへの答えを考えると、ロジックを次のようなものに修正する必要があります (疑似コード):
open Master;
open Transaction;
# Get initial records?
read first Master;
read first Transaction;
BATCH_LOOP:
while (!eof(Master) && !eof(Transaction))
{
while (Master.ID < Transaction.ID && !eof(Master))
{
write Master;
read next Master;
}
if (Master.ID > Transaction.ID)
{
report Missing Master for Transaction;
read next Transaction;
next BATCH_LOOP;
}
# Master.ID == Transaction.ID
Update Master from Transaction;
read next Transaction;
}
# At most one of the following two loop bodies is executed
while (!eof(Master))
{
read next Master;
write Master;
}
while (!eof(Transaction))
{
Report Missing Master;
read next Transaction;
}
ロジックを 2 回 (および 3 回) チェックしてください。しかし、それはあなたが必要とするものに近いです。
レキシカル ファイル ハンドルを使用します。
open my $master, "<", $master_file or die "Failed to open master file $master_file ($!)";
open my $trans, "<", $trans_file or die "Failed to open transaction file $trans_file ($!)";
それらは互いに独立して読むことができます。