daccame has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I've been looking for a way to compare the current line in a loop to the previous line in the loop. I've been looking all day and can't seem to find an answer.
What I have so far:
my $previous = ''; while (<>) { @gtf = split /\s+/, $_; chomp(); if ("$gtf[9]" ne "$previous") { $gtf[2] =~ tr/ex*/ex1/; } else { $gtf[2]++; } }
Basically, I want to compare item 9 of @gtf in the current iteration with item 9 of @gtf from the last iteration and if they are different, restart the ex counter at 1. $gtf[2] is "ex1" and increases by 1 every iteration. Thanks!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Comparing adjacent lines
by aaron_baugher (Curate) on Jul 10, 2012 at 02:08 UTC | |
by daccame (Initiate) on Jul 10, 2012 at 17:12 UTC | |
by daccame (Initiate) on Jul 12, 2012 at 14:27 UTC | |
by aaron_baugher (Curate) on Jul 12, 2012 at 15:29 UTC | |
by daccame (Initiate) on Jul 12, 2012 at 17:18 UTC | |
| |
Re: Comparing adjacent lines
by The Code Captain (Initiate) on Jul 09, 2012 at 23:56 UTC | |
Re: Comparing adjacent lines
by frozenwithjoy (Priest) on Jul 09, 2012 at 23:53 UTC | |
Re: Comparing adjacent lines
by sundialsvc4 (Abbot) on Jul 10, 2012 at 03:50 UTC |
Back to
Seekers of Perl Wisdom