Thank you for updating to properly format the code. Preliminary inspection reveals a few problems:
-
The scalar $found; is sitting all alone before the first foreach block and was probably meant to be a my $found = ''; statement. This suggests you are not running with warnings and strictures. Do yourself a big favor and use warnings; and use strict; in all your programs. Additionally, use diagnostics; is often very helpful to Perl beginners.
-
If there is or might be a newline at the end of the line you read from the keywords file, you don't deal with it. See chomp.
-
In your example, you have only a single line in the keyword file, but you read the file to an array (which you then improperly try to split). I don't understand this approach. If there may be multiple lines in the keyword file, keyword processing can be done in a loop, on a line-by-line basis:
-
Try to read a line;
-
If read was successful, pre-process line (e.g., remove any newline);
-
split keyword line on delimiter;
-
Add individual keywords to @values array. Update: Changed to @values from @data
-
The split statement
my @values = split(' ', @data, 9);
has problems.
-
You appear to be splitting on a single space, not the ',' (comma) delimiter that is shown in the example in the OP.
-
split only splits on a string, not on an array, @data in this case.
-
You are using a split limit count of 9, which I don't understand in the context of the stated problem.
You might want to break the problem apart: hard-code the @values array with some keywords and then get the Skype file read-and-scan operation right, then go back and attack the keyword read-parse-prepare part. (From a quick glance, I would say that the Skype file read-scan is very close to working. Oops: except that you are looping over the keyword file line array @data instead of the extracted keywords @values array. Better variable naming (e.g., @keywords instead of @values) might have prevented this. Also: improper index offset comparison spotted by johngg.)
Update: Added section on multi-line keword file.