Dear Perl users,

I have some problems wih the folowing algorithm:

File A:
---------------------
ID - 001
AD - Bill
AD - Castro
AD John

ID - 002
AD - Andrew
AD - Mike

etc.
---------------------
Then in the second file I have some values for each AD:

---------------------
Andrew - 10
Bill - 20
Castro - 20
John - 5
Mike - 10
----------------------
I wrote a script (with yours help) which sums all corresponding AD values from file B for particular ID in file A.

E.g.:
001 - 45       #ID is 001 and Bill (20) + Castro (20) + John (5) = 45
002 - 20       #ID is 002 and Andrew (10) + Mike (10) = 20
etc.

And now the main problem. I want to add File C, which will contain certain names, e.g.:
Castro
John
etc.


How to modify my script to sum only those AD's from file A, which not exists in file C.

E.g.: if Castro and John exists in file C, then the result must be:
001 - 45 #ID is 001 and Bill (20) = 20 -->omit Castro (20) and John (5)
002 - 20       #ID is 002 and Andrew (10) + Mike (10) = 20

Thanks in advance for any suggestions, notes, pointers...

Cheers, Andrej



And the script:

########################################
# first I read second file (File B)
while (<File B>) {
   chomp;
   my ($name,$value)=split / - /;
   $score{$name} = $value;
}

# and then I parse first file (File A)
while (<file A>) {
   chomp;
   if (/^ID/) {
       $ID = substr($_,6);
   }
   elsif (/^AD/) {
       $AD = substr($_,6);
       $Sum{$ID}+=$score{$AD};
   }
}

# and output
for my $id (sort keys %Sum) {
   print "$id - $Sum{$id}\n";

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to