Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Finding problem with finding keywords in arrays / files

by coreolyn (Parson)
on Sep 17, 2006 at 10:49 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://573395]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-24 09:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found