CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Searching and printing the occurrence of strings within an array

 



rakesh_01
New User

Sep 22, 2010, 10:18 AM

Post #1 of 1 (1543 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


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
Smile

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives