in reply to Help with pattern matching and calling wc -l

Why do you think that you have a few errors?

What is the following line supposed to do?

if ($file=qr/HybridViralBactContigsList.txt/){

(hint: You might want to read perlop for the difference between = and =~, and perlre for the meaning of . and anchors, and File::Basename for the general approach)

Replies are listed 'Best First'.
Re^2: Help with pattern matching and calling wc -l
by Anonymous Monk on Mar 10, 2010 at 12:56 UTC
    Thanks, I guess I should use =~ I also removed the . What I want the line of script to do: when I find a file with the string'HybridViralBact' I wanted to count the number of lines in that file. I think my main error now is with the wc -l syntax. Ther error is.

    Argument "3503 /outputMC38..." isn't numeric in subtraction (-) at Perl_Chimera_File_Summ.pl line 30.

    #!/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_C +himera Num_Virus_Virus_Chimera), "\n") ; while ($MG_Num <= 72) { @files=</g/bork6/mende/MGSimulation/hybridcontigs/outputMC38/*.MG$MG_N +um.*>; foreach $file (@files) { if ($file=~/HybridViralBactContigsList/){ $Num_Bact_Virus_Chimera=qx/wc -l $file/; $Num_Bact_Virus_Chimera=$Num_Bact_Virus_Chimera-1; } if ($file=~/HybridOnlyBactContigsList/){ $Num_Bact_Bact_Chimera=qx/wc -l $file/; $Num_Bact_Bact_Chimera=$Num_Bact_Bact_Chimera-1; } if ($file=~/HybridOnlyVirusContigsList/){ $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;
      $Num_Bact_Virus_Chimera=$Num_Bact_Virus_Chimera-1;

      Maybe you should check that $Num_Bact_Virus_Chimera contains what you think it does. See print:

      print "Got '$Num_Bact_Virus_Chimera' lines.