Home: Perl Programming Help: Regular Expressions:
Searching keywords within an array and displaying every occurrence of it



rakesh_01
New User

Sep 27, 2010, 12:35 PM


Views: 5893
Searching keywords within an array and displaying every occurrence of it

Hi,

I have a text file called keywords.txt that has the keywords call,please,urgent. I have another text file called Skypelogs.txt which contains a log of all the Skype chat conversations that has occurred so far. I need to search the file called Skypelogs.txt for every occurrence of every keyword locateed in keywords.txt , which are call, please, urgent and display that particular line on the screen. When it is finished, it should print " Scan completed " on the screen. I came up with a program, but for some reason, I am not able to get the split function to split the keywords within the file keywords.txt using the delimiter ',' and store it in an array. Can someone help me out with it as it is very important and urgent. Any help is much appreciated.

Code
 
#!/usr/bin/perl

open FILE,"keywords.txt" or die $!;

# read file into an array

my @data = <FILE>;

my @values = split(' ', @data, 9);

close (FILE);

open FILE,"Skypelogs.txt" or die $!;

# read file into another array

my @array = <FILE>;

$found;

foreach $var (@data)
{
foreach $line(@array)
{
if (index($var, $line) != "")
{
$found .= $line. "\n";
}
}
}
print $found;
# close file

close (FILE);


Thanks in advance.

Rakesh Vishwanath