Sophienz has asked for the wisdom of the Perl Monks concerning the following question:
Dear PerlMonks,
I'm having an issue with printing long strings. I build an array of 251 elements and join it with \t to print to a file. The problem is that the output randomly misses \t 's and sometimes both the \t and the last letter of the previous value.
I've tried using autoflush and printflush but the problems remain. Any suggestion would be much appreciated. This is the problem line at the moment:
$normal_fh->printflush(join("\t",@arrayToPrint)."\n");
UPDATED: Here is the code I am using
open my( $normal_fh ), ">>", $normalOut or die("Couldn't open NORM +AL $normalOut $!\n"); my @arrayToPrint; if ($nbGABlocks == 0) { @arrayToPrint = (); #print ("NoAlignmentBlocks!\n"); my @subArray = ($chrInterval,$startInterval,$endInterval,"NA", +"NA","NA"); my @naArray = ("NA","NA","NA","NA","NA","NA","NA") x scalar(@s +pecies); push(@arrayToPrint,@subArray); push(@arrayToPrint,@naArray); } NORMALBLOCK: foreach my $block (sort{$blocksHash{$a}{"orderBlock"} + <=> $blocksHash{$b}{"orderBlock"}} keys %blocksHash) { my $spNb = 0; my $order = $blocksHash{$block}{"orderBlock"}; @arrayToPrint = (); my @subArray = ($chrInterval,$startInterval,$endInterval,$bloc +k,$order,$warning); push(@arrayToPrint,@subArray); @subArray = (); SP: foreach my $sp (@species) { my $newSp = $speciesCorrespond{$sp}; $spNb++; if (exists($blocksHash{$block}{$newSp})) { my $chr = $blocksHash{$block}{$newSp}{"chr"}; my $start = $blocksHash{$block}{$newSp}{"start"}; my $end = $blocksHash{$block}{$newSp}{"end"}; my $strand = $blocksHash{$block}{$newSp}{"strand"}; my $size = $blocksHash{$block}{$newSp}{"sizeBlock"}; my $comment = $spBlocksHash{$newSp}{$block}{"comment"} +; @subArray = ($newSp,$chr,$start,$end,$strand,$size,$co +mment); push(@arrayToPrint,@subArray); @subArray = (); } else { @subArray = ($newSp,"NA","NA","NA","NA","NA","NA"); push(@arrayToPrint,@subArray); @subArray = (); } } my $printing = join("\t",@arrayToPrint); $" = "\t"; $normal_fh->printflush("$printing\n"); }
The output is very long, but here is a sample, where you can see that for some lines, instead of getting: spermophilus_tridecemlineatus\tNA, I get spermophilus_tridecemlineatuNA:
rattus_norvegicus NA NA NA NA NA NA dipodomys_ord +ii NA NA NA NA NA NA spermophilus_tridecemlineat +us NA NA NA NA NA NA ochotona_princeps NA +NA NA NA NA NA oryctolagus_cuniculus NA NA NA + NA NA NA rattus_norvegicus 5 13171176 13038994 -1 132183 NotC +ontiguous_326154Gap dipodomys_ordii NA NA NA NA NA + NA spermophilus_tridecemlineatus NA NA NA NA NA + NA ochotona_princeps NA NA NA NA NA NA ory +ctolagus_cuniculus NA NA NA NA NA NA rattus_norvegicus NA NA NA NA NA NA dipodomys_ord +ii NA NA NA NA NA NA spermophilus_tridecemlineat +uNA NA NA NA NA NA ochotona_princeps NA NA + NA NA NA NA oryctolagus_cuniculus NA NA NA N +A NA NA rattus_norvegicus NA NA NA NA NA NA dipodomys_ord +ii NA NA NA NA NA NA spermophilus_tridecemlineat +uNA NA NA NA NA NA ochotona_princeps NA NA + NA NA NA NA oryctolagus_cuniculus NA NA NA N +A NA NA rattus_norvegicus 5 13004812 12917777 -1 87036 NotCo +ntiguous_253399Gap dipodomys_ordii NA NA NA NA NA + NA spermophilus_tridecemlineatus NA NA NA NA NA + NA ochotona_princeps NA NA NA NA NA NA oryc +tolagus_cuniculuNA NA NA NA NA NA rattus_norvegicus 5 12917776 12899724 -1 18053 Conti +guous dipodomys_ordii NA NA NA NA NA NA sperm +ophilus_tridecemlineatus NA NA NA NA NA NA ochot +ona_princeps NA NA NA NA NA NA oryctolagus_cunic +ulus NA NA NA NA NA NA
Thanks a lot for your help,
Sophie.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Missing \t in print output
by pme (Monsignor) on Jul 14, 2015 at 11:52 UTC | |
by Sophienz (Acolyte) on Jul 14, 2015 at 13:18 UTC | |
Re: Missing \t in print output
by Discipulus (Canon) on Jul 14, 2015 at 12:03 UTC | |
Re: Missing \t in print output
by 1nickt (Canon) on Jul 14, 2015 at 11:52 UTC | |
Re: Missing \t in print output
by ww (Archbishop) on Jul 14, 2015 at 18:24 UTC | |
by Sophienz (Acolyte) on Jul 15, 2015 at 09:53 UTC | |
by ww (Archbishop) on Jul 15, 2015 at 12:08 UTC | |
Re: Missing \t in print output
by akuk (Beadle) on Jul 14, 2015 at 11:50 UTC | |
Re: Missing \t in print output
by Sophienz (Acolyte) on Jul 15, 2015 at 13:10 UTC | |
by Anonymous Monk on Jul 15, 2015 at 13:15 UTC | |
by Sophienz (Acolyte) on Jul 15, 2015 at 13:40 UTC | |
Re: Missing \t in print output
by Anonymous Monk on Jul 15, 2015 at 11:35 UTC | |
Re: Missing \t in print output
by Sophienz (Acolyte) on Jul 14, 2015 at 15:11 UTC | |
by ww (Archbishop) on Jul 14, 2015 at 18:33 UTC | |
by Anonymous Monk on Jul 14, 2015 at 16:10 UTC | |
by Sophienz (Acolyte) on Jul 15, 2015 at 10:03 UTC | |
Re: Missing \t in print output
by Anonymous Monk on Jul 15, 2015 at 11:01 UTC | |
by Sophienz (Acolyte) on Jul 15, 2015 at 11:15 UTC | |
by 1nickt (Canon) on Jul 15, 2015 at 11:57 UTC | |
by Sophienz (Acolyte) on Jul 15, 2015 at 12:35 UTC | |
by Anonymous Monk on Jul 15, 2015 at 11:56 UTC | |
by Sophienz (Acolyte) on Jul 15, 2015 at 12:58 UTC | |
by Anonymous Monk on Jul 15, 2015 at 12:07 UTC |