john.tm has asked for the wisdom of the Perl Monks concerning the following question:
INPUT output is jon 22 james 12 ken 22 jack 33 jim 11 harry 7 dave 9 grant 12 matt 74 malc 12
output i want isINPUT1 output is jon 2 james 1 ken 8 jack 5 jim 1 harry 51 dave 22
code i have so far isjon 24 james 13 ken 30 jack 38 jim 12 harry 58 dave 31 grant 12 matt 74 malc 12
my %seen; seek INPUT, 0, 0; while (<INPUT>) { chomp; my $line = $_; my @elements = split (",", $line); my $col_name = $elements[1]; #print " $col_name \n" if ! $seen{$col_name}++; } while ( my ( $col_name, $times_seen ) = each %seen ) { my $loc_total = $times_seen * $dd; print "\n"; print " $col_name \t\t : = $loc_total"; printf OUTPUT "%-34s = %15s\n", $col_name , " $loc_total "; } ############## ################### my %seen2; seek INPUT1, 0, 0; while (<INPUT1>) { chomp; my $line = $_; my @elements1 = split (",", $line); my $col_name = $elements1[1]; my $col_type = $elements1[5]; $seen2{$col_name}++ if $col_type eq "YES"; } while ( my ( $col_name, $times_seen2 ) = each %seen2 ) { my $loc_total = $times_seen2 ; print "\n $col_name \t\t= $loc_total"; printf OUTPUT "%-34s = %15s\n", $col_name , $times_seen2 ; } close INPUT;
|
|---|