How to grep read file in perl -


i read file in perl, after, user can input string , grep try find string inputted in file read. exit when user input nothing or space character. here's code not working:

#! usr/bin/perl use warnings; use strict;  open matchstring,"matchstring"; @lines = <matchstring>;  while (<>) {     chomp;     @match = grep {/\b$_\b/s} @lines;     print @match;     } 

i'm still lacking condition exit once nothing inputted or newline or space character.

there possible problem in example my @match = grep {/\b$_\b/s} @lines; grep not working user input, content of @lines. this:

grep { $lines[index] =~ /\b$lines[index]\b/s } 

and want this:

while (my $input = <>) {   chomp($input);   last if $input =~ /^ \s* $/x; # exit loop if no input or whitespaces    @match = grep { /\b$input\b/s } @lines;   print @match; } 

Comments