What do you want to happen to the data after you've made these changes? Print it out to a file? Save it to a database? Push it onto an array created outside the loop? As it stands, you make changes to the @gtf array, and then it's clobbered when the loop restarts and splits the next line into it. Since you haven't localized it to the loop, the last line will remain in it after the loop exits, but I doubt that's what you want.
I'll go through your code and add some comments below, followed by my suggestions:
my $previous = ''; while (<>) { @gtf = split /\s+/, $_; chomp(); # switch those two to chomp the line before you split it, # otherwise your chomp is meaningless. Also, those are # the default arguments to split: while(<>){ chomp; my @gtf = split; if ("$gtf[9]" ne "$previous") { # don't put quotes around single variables; potentially buggy if( $gtf[9] ne $previous ){ $gtf[2] =~ tr/ex*/ex1/; # this probably doesn't do what you want. # tr/// transliterates characters: here e becomes e, # x becomes x, and a literal asterisk becomes 1. # If you want to reset $gtf[2] back to 'ex1', just do so: $gtf[2] = 'ex1'; } else { $gtf[2]++; # this may bite you too. $x='ex9'; $x++; $x=='ey0' # you probably want to increment just the number: $gtf[2] =~ s/(\d+)/$1+1/e; } # now save $gtf[9] in $previous so it can be compared to the next li +ne $previous = $gtf[9]; # here is where you would print out the array values, or do whatever + you like with them }
Aaron B.
Available for small or large Perl jobs; see my home node.
In reply to Re: Comparing adjacent lines
by aaron_baugher
in thread Comparing adjacent lines
by daccame
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |