Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Finding problem with finding keywords in arrays / files

by coreolyn (Parson)
on Sep 17, 2006 at 10:49 UTC( #573395=note: print w/replies, xml ) Need Help??


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

This probably isn't THE most efficient way to do this but it does what you are trying to achieve.

#!/usr/local/bin/perl -w use strict; open(DATA, "data.txt") or die "Error opening 'data.txt' $!\n"; my @data = <DATA>; open(KEYWORDS, '<', "keyword.txt") or die "Error opening 'keyword.txt' + $!\n"; my @keywd = <KEYWORDS>; close DATA; close KEYWORDS; foreach my $data ( @data ) { chomp($data); foreach my $keyword (@keywd) { chomp($keyword); if ( $data =~ /$keyword/i ) { print "Match \$data = $data and \$keyword = $keyword\n"; } } }

Replies are listed 'Best First'.
Re^2: Finding problem with finding keywords in arrays / files
by Anonymous Monk on Sep 17, 2006 at 10:59 UTC
    chomp(my @data = do { open my $f, "data.txt" or die "Error opening ``data.txt'': $!"; <$f> });
Re^2: Finding problem with finding keywords in arrays / files
by akirostar (Novice) on Sep 17, 2006 at 13:26 UTC
    Hi core, I tried what you have written, with regards to the IF loop, the program will enter it no matter how, is it possible to jus t enter into the loop during the actual matching? thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://573395]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2016-08-30 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (410 votes). Check out past polls.