Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Strange output problem

by Lotus1 (Chaplain)
on Apr 12, 2012 at 17:59 UTC ( #964801=note: print w/ replies, xml ) Need Help??


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;


Comment on Re: Strange output problem
Download Code
Re^2: Strange output problem
by iangibson (Scribe) on Apr 12, 2012 at 18:46 UTC

    Thanks! It looks like that was the problem. I simply added a

     close $out_file;

    between the two parts of the program, and the output is now correct. I'd never have thought of that .. better get into the habit of closing filehandles when I'm done with them!

    Thanks again.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://964801]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2014-12-27 04:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls