#!/usr/bin/perl -l use strict; use warnings; my @old=split ' ', <DATA>; print "@old"; while (<DATA>) { my @cur=split; print "@cur[0,1]" eq "@old[0,1]" ? $cur[2] : "@cur"; @old=@cur; } __END__ foo bar baz foo fred baz foo fred burz bar baz burp
Additional checks and adaptation to current situation are left as an exercise to the reader.
Although it should be clear that this is meant as a minimal example, I'd like to stress that "@cur[0,1]" eq "@old[0,1]" is a simple minded equality test based on joining on $", which happens to be a space by default. Of course this works here, but is bound to be unreliable in a realistic situation, and you may have to roll a more sophisticated test yourself.
In reply to Re: compare current row with previous row
by blazar
in thread compare current row with previous row
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |