
rakesh_01
New User
Sep 22, 2010, 10:18 AM
Post #1 of 1
(2738 views)
|
Searching and printing the occurrence of strings within an array
|
Can't Post
|
|
Hi, I have a text file called keywords.txt that has a few keywords stored in it. I have another text file that has the logs of all the chat conversations that occurred on Skype. I have stored the keywords present within keywords.txt in an array and i have stored the chat logs of Skype into another array. I want to print every occurrence of every keyword in the second array. I have managed to come up with the following code
#!/usr/bin/perl open FILE,"keywords.txt" or die $!; # read file into an array my @data = <FILE>; my @values = join("\n",@data), "\n"; close (FILE); open FILE,"Skypelogs.txt" or die $!; # read file into another array my @array = <FILE>; $found; foreach my $var (@values) { foreach my $line(@array) { if(grep($var, $line)) { $found .= $line. "\n"; } } print $found; } # close file close (FILE); but i am not able to get to match the occurrence of the keywords with the array that stores the Skypelogs. I would really appreciate help on this. Thanks in advance Rakesh
|