Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This is my code how to do search with pattern matching and out put the result?
#!/usr/local/bin/perl $file = 'thesaurus'; # Name the file open(INFO, $file); # Open the file @lines = $a; # Read it into an array print " What are you looking for? "; # Ask for input $a = <STDIN>; # Get input chop $a; # Remove the newline at + end print "@lines\n";

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How to do pattern matching and output the results?
by repson (Chaplain) on Nov 23, 2000 at 09:31 UTC
    You might want to try:
    print join("\n",grep {/$a/i} @lines);
    to print any lines containing $a.
    And change
    @lines=$a   # this should be an error if you use warnings.
    to
    @lines=<INFO>; close INFO;

    Originally posted as a Categorized Answer.