in reply to Trying to make a search Part 2
It points out potential problems with your code. (This code doesn't have any, but it is a good technique to use anyway).use warnings;
In this case I think your problem is that you're double-chomping $word. When reading input you only need to chomp once to remove the line terminator (CR/LF).
print "Search for what: "; chomp(my $search = <STDIN>); @words = split(/ /, $search); open(DATA, "data.txt") or die "error opening file $!"; @data = <DATA>; foreach $data(@data) { foreach $word(@words) { if ($data =~ /$word/) { print $data; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Trying to make a search Part 2
by Adam (Vicar) on Jun 05, 2000 at 19:58 UTC |