Hi
I have a array in which I need to count the number of ocurrence of a particular word
for eg I need to count no of times a word "test" , "test2" occurs in a array @list.
(The contents of the array is around 100 lines)
Code:
[code=perl]
open(FH3, "sample.txt ");
while(<FH3>)
{
@array=$_;
print @array;
}
close(FH3);
my %counts = ();
for (@array) {
$counts{$_}++;
}
foreach my $keys (keys %counts) {
print "$keys = $counts{$keys}\ n";
}
if($counts{$key s}==1)
{
print "$keys = $counts{$keys}\ n";
}
[/code]
I dont want the count for all the words in the array and I need the same only for a given Input word...
Can you help me in this regard..
Thanks In Advance
I have a array in which I need to count the number of ocurrence of a particular word
for eg I need to count no of times a word "test" , "test2" occurs in a array @list.
(The contents of the array is around 100 lines)
Code:
[code=perl]
open(FH3, "sample.txt ");
while(<FH3>)
{
@array=$_;
print @array;
}
close(FH3);
my %counts = ();
for (@array) {
$counts{$_}++;
}
foreach my $keys (keys %counts) {
print "$keys = $counts{$keys}\ n";
}
if($counts{$key s}==1)
{
print "$keys = $counts{$keys}\ n";
}
[/code]
I dont want the count for all the words in the array and I need the same only for a given Input word...
Can you help me in this regard..
Thanks In Advance
Comment