I'm having some difficulty with the print function. I am setting up a spreadsheet of different companies and the products that they carry which matches with another company. For instance, if company A has the same product as the company that I'm comparing it to, the column would have a Y printed in it. If company A doesn't have this product, a N would be printed. With doing the actual comparison, I am having no difficulty. However, I would then like to print a summary count of the respective "y"'s and "N"'s. I have established a counter and the number is coming out correct but I cannot seem to get it to print where I want it to print without having numerous duplications of the statement. If I print within the while loop, I end up with several hundred lines from the counter all saying the same thing. If I print at the end of all of my while loops, I end up with the line printed on line #921, which is far from where I need it. Basically what I'm asking is if there's a way to place the print function in the while loop and get it to print only one time?

!#/usr/bin/perl -w open (IN, "C:/Work/Cytokine/ING_cytokines_20080805.txt"); while (<IN>){ #start while loop chomp; @t=split(/\t/,$_); #splits file and stores values in $_ $ING{$t[9]}=1; #selects one column from input file } # end while loop close IN; open (OUT, ">C:/work/Cytokine/Cytokine.txt") or die "cannot open"; open (IN, "C:/work/Cytokine/CytokineArrays.txt") or die "cannot open"; while(<IN>){ #start of while loop chomp; @cytokine=split(/\t/,$_); #splits input file and stores + in $_ #begin if statements if($cytokine[1]=~/\S+/ and exists $ING{$cytokine[1]}){ #grou +p 1 - compares second row of input file to $ING print OUT "$cytokine[0]\t$cytokine[1]\tY\t"; $SABioY++;} elsif ($cytokine[1] =~ /\d+/) { print OUT "$cytokine[0]\t$cytokine[1]\tN\t"; $SABioN++;} else { print OUT "$cytokine[0]\t$cytokine[1]\t\t"; } if ($SABioY ge 0) {print OUT "SA Biosciences has $SABioY prod +ucts."}; if ($SABioN ge 0) {print OUT "SA Biosciences does not have $SABi +oN products."}; if($cytokine[3]=~/\S+/ and exists $ING{$cytokine[3]}){ #grou +p 2 print OUT "$cytokine[2]\t$cytokine[3]\tY\t";} elsif ($cytokine[3] =~ /\d+/) { print OUT "$cytokine[2]\t$cytokine[3]\tN\t"; }else { print OUT "$cytokine[2]\t$cytokine[3]\t\t"; } if($cytokine[5]=~/\S+/ and exists $ING{$cytokine[5]}){ #grou +p 3 print OUT "$cytokine[4]\t$cytokine[5]\tY\t";} elsif ($cytokine[5] =~ /\d+/) { print OUT "$cytokine[4]\t$cytokine[5]\tN\t"; }else { print OUT "$cytokine[4]\t$cytokine[5]\t\t"; } if($cytokine[7]=~/\S+/ and exists $ING{$cytokine[7]}){ #grou +p 4 print OUT "$cytokine[6]\t$cytokine[7]\tY\t";} elsif ($cytokine[7] =~ /\d+/) { print OUT "$cytokine[6]\t$cytokine[7]\tN\t"; }else { print OUT "$cytokine[6]\t$cytokine[7]\t\t"; } if($cytokine[9]=~/\S+/ and exists $ING{$cytokine[9]}){ #grou +p 5 print OUT "$cytokine[8]\t$cytokine[9]\tY\t";} elsif ($cytokine[9] =~ /\d+/) { print OUT "$cytokine[8]\t$cytokine[9]\tN\t"; }else { print OUT "$cytokine[8]\t$cytokine[9]\t\t"; } if($cytokine[11]=~/\S+/ and exists $ING{$cytokine[11]}){ #gr +oup 6 print OUT "$cytokine[10]\t$cytokine[11]\tY\t";} elsif ($cytokine[11] =~ /\d+/) { print OUT "$cytokine[10]\t$cytokine[11]\tN\t"; }else { print OUT "$cytokine[10]\t$cytokine[11]\t\t"; } if($cytokine[13]=~/\S+/ and exists $ING{$cytokine[13]}){ #gr +oup 7 print OUT "$cytokine[12]\t$cytokine[13]\tY\t";} elsif ($cytokine[13] =~ /\d+/) { print OUT "$cytokine[12]\t$cytokine[13]\tN\t"; }else { print OUT "$cytokine[12]\t$cytokine[13]\t\t"; } if($cytokine[15]=~/\S+/ and exists $ING{$cytokine[15]}){ #gr +oup 8 print OUT "$cytokine[14]\t$cytokine[15]\tY\t";} elsif ($cytokine[15] =~ /\d+/) { print OUT "$cytokine[14]\t$cytokine[15]\tN\t"; }else { print OUT "$cytokine[14]\t$cytokine[15]\t\t"; } if($cytokine[17]=~/\S+/ and exists $ING{$cytokine[17]}){ #gr +oup 9 print OUT "$cytokine[16]\t$cytokine[17]\tY\t";} elsif ($cytokine[17] =~ /\d+/) { print OUT "$cytokine[16]\t$cytokine[17]\tN\t"; }else { print OUT "$cytokine[16]\t$cytokine[17]\t\t"; } if($cytokine[19]=~/\S+/ and exists $ING{$cytokine[19]}){ #g +roup 10 print OUT "$cytokine[16]\t$cytokine[19]\tY\t";} elsif ($cytokine[19] =~ /\d+/) { print OUT "$cytokine[18]\t$cytokine[19]\tN\t"; }else { print OUT "$cytokine[18]\t$cytokine[19]\t\t"; } if($cytokine[21]=~/\S+/ and exists $ING{$cytokine[21]}){ #gr +oup 11 print OUT "$cytokine[20]\t$cytokine[21]\tY\t";} elsif ($cytokine[21] =~ /\d+/) { print OUT "$cytokine[20]\t$cytokine[21]\tN\t"; }else { print OUT "$cytokine[20]\t$cytokine[21]\t\t"; } if($cytokine[23]=~/\S+/ and exists $ING{$cytokine[23]}){ #gr +oup 12 (\n used in the final group for formatting) print OUT "$cytokine[22]\t$cytokine[23]\tY\t\n";} elsif ($cytokine[23] =~ /\d+/) { print OUT "$cytokine[22]\t$cytokine[23]\tN\t\n"; }else { print OUT "$cytokine[22]\t$cytokine[23]\t\t\n"; } } # end of while loop close IN; close OUT;

In reply to Print function by de2425

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.