in reply to Print function

Looks to me like all the sections except the first one look the same, right? Why do you repeat the code then? Use a loop:

for my $id (1..11) { if($cytokine[2*$id+1]=~/\S+/ and exists $ING{$cytokine[2*$id+1]}) { print OUT "$cytokine[2*$id]\t$cytokine[2*$id+1]\tY\t"; } elsif ($cytokine[2*$id+1] =~ /\d+/) { print OUT "$cytokine[2*$id]\t$cytokine[2*$id+1]\tN\t"; } else { print OUT "$cytokine[2*$id]\t$cytokine[2*$id+1]\t\t"; } }
Also please do be consistent with the code formatting.

This aside ... I do not understand when do you want to print the counts. Line #921 doesn't mean anything to me. Do you want to pring it after you process all the lines from CytokineArrays.txt? Or earlier? And if so, when?

Replies are listed 'Best First'.
Re^2: Print function
by de2425 (Sexton) on Sep 02, 2008 at 16:10 UTC
    Thank you for responding. I very much appreciate it as I'm a complete novice at this. I am sorry if I'm not more clear. When I was referring to line #921, what I was trying to say is that there are approximately 900 lines of blank space between where my output ends and the totals are printed when I place the total print statement outside the initial while loop. If I place the print statement for the count inside the while statement, it prints the statements approximately 900 times. I cannot figure out why it is doing this. I would prefer to print totals after each different company is printed.

      Are those lines empty or full of tab characters? Maybe the CytokineArrays.txt file ends by some 900 empty lines. Try to add

      next unless /\S/;
      after the chomp; in the second loop.

      Also, there is no difference between $var =~ /\S+/ and $var =~ /\S/. Except that the later will probably be quicker. Both return true whenever there is at least one non-whitespace-character anywhere in the $var. Same with the \d. Maybe you wanted $var =~ /^\S+$/. Which means ... make sure the $var contains only non-whitespace-characters and is not empty.

      Update: fixed the typo noticed by jwkrahn. I meant \S+ and wrote \s+.

        Maybe you wanted $var =~ /^\s+$/. Which means ... make sure the $var contains only non-whitespace-characters and is not empty.

        I think that you meant $var =~ /^\S+$/ for non-whitespace-characters?

        Thank you very much. That did the trick.