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

Post #1 of 1 (2001 views)
Searching keywords within an array and displaying every occurrence of it Can't Post

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

 
 


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

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