Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Missing \t in print output by Sophienz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found