in reply to Trying to make a search Part 2

One thing you might find handy is
use warnings;
It points out potential problems with your code. (This code doesn't have any, but it is a good technique to use anyway).

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
    Double chomping doesn't hurt anything. Yeah, its a waste of cycles, but chomp only removes white space characters. Double choping on the other hand would be bad (unless that was what you wanted to do)