in reply to Re: Piping many individual files into a single perl script
in thread Piping many individual files into a single perl script
A sample of what I received: File# A B C 1 5 6 3 What I wanted: File# A B C 1 2 1 0 2 2 4 2 3 1 1 1This is my code:
What am I doing wrong? Edit: Thanks for the help so far!#!C:\Perl use strict; BEGIN{ @ARGV=map glob, @ARGV; } open(RES, ">>results.txt"); print RES "File Number A A% B B% Null Null%\n"; my $A=0; #these three lines set my initial counts at zero my $B=0; my $null=0; my $filenum=0; while (<>){ chomp($_); if ($_ eq "stringa"){ $A++;} elsif ($_ eq "stringb"){ $B++;} else { $null++; } } my $popa=$A/1000; #these lines determine what percent of the populatio +n the strings represent my $popa=sprintf('%.2f',$popa); #cut the percentages to two decimal pl +aces my $popb=$B/1000; my $popb=sprintf('%.2f',$popb); my $popnull=$null/1000; my $popnull=sprintf('%.2f',$popnull); my $filenum++; #Add one to my filenumber print RES "$filenum $A $popa $B $popb $null $pop +null\n"; #print the results out to the "results" file
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Piping many individual files into a single perl script
by BrowserUk (Patriarch) on Sep 28, 2008 at 14:27 UTC | |
by broomduster (Priest) on Sep 28, 2008 at 14:47 UTC | |
by BrowserUk (Patriarch) on Sep 28, 2008 at 15:30 UTC | |
|
Re^3: Piping many individual files into a single perl script
by graff (Chancellor) on Sep 28, 2008 at 15:22 UTC | |
|
Re^3: Piping many individual files into a single perl script
by apl (Monsignor) on Sep 28, 2008 at 11:52 UTC | |
|
Re^3: Piping many individual files into a single perl script
by blazar (Canon) on Sep 29, 2008 at 14:45 UTC |