AWallBuilder:

You should show some sample input, the actual output and expected output to make it simpler for us to see the error. As it is, we need to either:

Also, if you indent your code to show the structure, it makes things a bit easier for us to see how it works. It should also help you when you're creating/modifying/debugging it. It even makes some errors pretty obvious, like so:

#!/usr/bin/perl -w my $Num_Bact_Virus_Chimera=0; my $Num_Bact_Bact_Chimera=0; my $Num_Virus_Virus_Chimera=0; my $outfile='MC38_ChimeraTable.txt'; my $MG_Num=1; open(OUT, ">$outfile") || die "Can't open outputfile $!\n"; print OUT join("\t",qw ( MG_Num Num_Bact_Virus_Chimeras Num_Bact_Bact_Chimera Num_Virus_Virus_Chimera ), "\n") ; while ($MG_Num <= 72) { @files=</outputMC38/*.MG$MG_Num.*>; foreach $file (@files) { if ($file=qr/HybridViralBactContigsList.txt/){ $Num_Bact_Virus_Chimera = qx/wc -l $file/; $Num_Bact_Virus_Chimera=$Num_Bact_Virus_Chimera-1; } if ($file=qr/HybridOnlyBactContigsList.txt/){ $Num_Bact_Bact_Chimera= qx/wc -l $file/; $Num_Bact_Bact_Chimera=$Num_Bact_Bact_Chimera-1; } if ($file=qr/HybridOnlyVirusContigsList.txt/){ $Num_Virus_Virus_Chimera=qx/wc -l $file/; $Num_Virus_Virus_Chimera=$Num_Virus_Virus_Chimera-1; } print OUT join("\t", $MG_Num,$Num_Bact_Virus_Chimera, $Num_Bact_Bact_Chimera, $Num_Virus_Virus_Chimera, "\n"); } } $MG_Num=$MG_Num+1;

Now that the code has some visual structure, one error immediately sticks out: Your while loop is checking when $MG_Num reaches 72, but you don't modify $MG_Num inside your loop. You only change it after the end of your while loop. I'm sure that's only one of your errors, but as you don't have sample data, expected and actual output and the error message, I'll just stop here.... ;^)

...roboticus


In reply to Re: Help with pattern matching and calling wc -l by roboticus
in thread Help with pattern matching and calling wc -l by AWallBuilder

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.