in reply to While loop stops after reading new line?
How do you know your script stopped reading after finding the first header? Are you sure your file contains more than one header?use strict; use warnings; my $filename = 'fasta.txt'; open my $FILE, '<', $filename or die "Could not open $filename: $!"; while(my $line = <$FILE>) { if($line=~/^>.*unknown/ ) { $line .= <DATA>; print $line; } } close $FILE;
I ran the above on the following data:
Output:test not this > unknown print this no no no again > known (not this header) got you! no way Jose > HEADER unknown Yessir! not this line throw this away
> unknown print this > HEADER unknown Yessir!
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
|
|---|