http://www.perlmonks.org?node_id=964801


in reply to Strange output problem

I noticed that you re-open the same file from $out_file as $new_in_file without closing $out_file first. Seems like buffering could be an issue here.

I tried your program with a smaller number of rows and columns and found that with the close statement before the reopen I got output in the final processed file and without it I got a blank file. The intermediary file looked good in both cases. Maybe the final data to the intermediary gets written when the program ends and that first file handle is closed. I don't want to troubleshoot much here until you have a look at using close.

Update: I thought of an easy way to test my idea about buffering. I made a copy of the intermediary file then closed the intermediary file then made another copy. The first copy was empty the second had everything in it.

# Remove unnecessary rows, clean up the SNPs and put into CSV format: open my $new_in_file, '<', "chr${chr_num}_exome_snps_only_transposed_$ +cont" or die "Cannot open new input file: $!"; ################################## # I added the following lines # open my $temp, '>', 'transposed_copy' or die "Cannot open transposed_copy: $!"; while(<$new_in_file>) { print $temp $_; } close $temp; close $out_file; open $temp, '>', 'transposed_copy2' or die "Cannot open transposed_copy2: $!"; while(<$new_in_file>) { print $temp $_; } close $temp;