Greetings monks,
I am currently trying to solve a loop riddle that has bested me.
The problem:
I am trying to take the first 16 lines of a single file, and populate those same 16 lines in 34 different (but incrementally named) files.
My current code:
$fh is the file im trying to take the 16 lines from, FYImy $filename = "../../Annotation_output"; for (my $i=0; $i<=33; $i++) { my $file_count = $i; open(my $new_fh, '>>', ("$filename" . "$file_count" . ".vcf")); my $count = 0; while (<$fh>) { print $new_fh "$_"; $count++; if ($count == 16) { last; } } }
I have had the first file (Annotation_output0.vcf) gain the 16 lines needed, but never any files afterward.
Common outputs have included having each of the 34 files gain 16 lines with the while loop never reseting (So Annotation_output0.vcf = lines 0-15, Annotation_output1.vcf = lines 16-31, Annotation_output2.vcf = lines 32-47, and so on), as well as seeing just output0.vcf gain 16 lines while output1.vcf gains the entirety of the while loop, never advancing past $i = 2
Any help is appreciated!
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |