AWallBuilder has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with pattern matching and calling wc -l
by roboticus (Chancellor) on Mar 10, 2010 at 12:58 UTC | |
by Anonymous Monk on Mar 10, 2010 at 13:30 UTC | |
by roboticus (Chancellor) on Mar 11, 2010 at 16:15 UTC | |
|
Re: Help with pattern matching and calling wc -l
by Corion (Patriarch) on Mar 10, 2010 at 12:25 UTC | |
by Anonymous Monk on Mar 10, 2010 at 12:56 UTC | |
by Corion (Patriarch) on Mar 10, 2010 at 12:59 UTC | |
|
Re: Help with pattern matching and calling wc -l
by cdarke (Prior) on Mar 10, 2010 at 12:51 UTC |