Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Strange output problem

by Lotus1 (Curate)
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;

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://964801]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2018-01-18 14:31 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (212 votes). Check out past polls.