Hello dears,

I want to count words in the following file:
------------------------------
ID- some number
TI- some text BB
AB- some text A BB
AU- some text

ID- some number
TI- some GGG text
AB- some text GGG
AU- some text

ID- some number
TI- some text
AB- some text Z
AU- some text
------------------------------

I wrote the script which parses througt the file and return the total number of words, defined in @list. Here is the problem. There could be more then one equal word in each record (see the first record where BB occurs twice).

I don't know, how to modify my code; so if there are multiple same words in a record, frequency of each word per record does not exceed 1.

Best, Andrej

while (<>){
     $/="\n\n"; #set input separator to read record
     $/="\n"; #set input separator to parse within a record
     chomp;
     if(/^TI.+/){
           foreach $w (split){
                  $wds++ if defined($words{$w})
           }
     }
}

print "\n$wds words"; #print frequency of words, defined in @list
----------------------------------------------------------------



--
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