in reply to What went wrong with this change in code?
In the original you are searching for two strings in the same line but in the new version you are searching for one string in one line and the other string in the next line.
Also, you are using the high precedence || operator which means that the program will not die if open fails because you are testing the boolean state of the string 'sample.fa' or the string '>modsample.fa' which are always true.
You probably want something like this:
open IN, '<', 'sample.fa' or die "Could not open 'sample.fa' becau +se: $!"; open OUT, '>', 'modsample.fa' or die "Could not open 'modsample.fa' be +cause: $!"; my $previous; while ( my $line = <IN> ) { if ( $previous && $line =~ /mamma/ && $line =~ /mia/ ) { print OUT $previous, $line; } else { print "."; } $previous = $line }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: What went wrong with this change in code?
by naturalsciences (Beadle) on Nov 10, 2011 at 11:32 UTC |