Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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"; } } }


Comment on Re: Finding problem with finding keywords in arrays / files
Download Code
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.
Reaped: Re^2: Finding problem with finding keywords in arrays / files
by NodeReaper (Curate) on Sep 17, 2006 at 14:30 UTC

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 musing on the Monastery: (7)
As of 2015-07-07 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls