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
In reply to Re: Finding problem with finding keywords in arrays / files
by davido
in thread Finding problem with finding keywords in arrays / files
by akirostar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |