in reply to Re: How to Save a variable outside of a loop
in thread How to Save a variable outside of a loop
You also need to skip the comparison for the first line of data.Or you could just give an initial dummy value to the two previous variables, thereby saving some steps within the loop:
#!/usr/bin/perl use warnings; use strict; my ($prev_l, $prev_p) = ("", ""); while(<>){ my $hitlength; my $prevalence; my $line = $_; chomp $line; if ($line =~ /^[\d]/){ my @hitline = split(/,/ , $line); $hitlength = $hitline[4]; $prevalence = $hitline[65]; if( $hitlength == $prev_l and $prevalence == $prev_p ){ next; } else { print "$line\n"; } $prev_l = $hitlength; $prev_p = $prevalence; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How to Save a variable outside of a loop
by AnomalousMonk (Archbishop) on Aug 01, 2015 at 10:38 UTC | |
by Laurent_R (Canon) on Aug 01, 2015 at 12:18 UTC | |
|
Re^3: How to Save a variable outside of a loop
by poj (Abbot) on Aug 01, 2015 at 10:48 UTC |