I am trying to write a perl script that loops through the files in a directory. First I want to find all the files that have 'MG1' in the name, then I want to count the lines in three different files (based on the filename). I then want to loop through this until MG72. And output the data as a table.
I think I have a few errors. I'm not sure about the pattern matching for the file name, and I don't think I'm calling wc-l properly.
Any advice? thanks
#!/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=</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;
In reply to Help with pattern matching and calling wc -l by AWallBuilder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |