in reply to Finding problem with finding keywords in arrays / files

Here is how I would probably do it, assuming your keyword matches are literal (not patterns).

use strict; use warnings; open my $keyword_fh, '<', 'keywords.txt' or die $! my %keywords; while ( <$keyword_fh> ) { chomp; $keywords{ $_ } = ''; } close $keyword_fh; open my $data_fh, '<', 'data.txt' or die $!; while( my $line = <$data_fh> ) { chomp $line ; my @found = grep { exists $keywords{ $_ } } $line =~ m/([^\W\d_]+)/g; print "Line $.: @found\n"; } close $data_fh;

This assumes 'words' are entirely alphabetical (no embedded characters such as '-' or " ' " (apostrophe)). It could be modified to deal with those too.


Dave

Replies are listed 'Best First'.
Re^2: Finding problem with finding keywords in arrays / files
by akirostar (Novice) on Sep 17, 2006 at 19:20 UTC
    This is nice.. Thanks sensei.. learn something again. Any chance you know how to use perl to manipulate vectors to XML?