Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I want to search for coulours and have the whole block as a result. thankscolours red blue yellow
#!/usr/local/bin/perl use strict; my $file = 'thesaurus'; # Name the fil +e open(INFO,$file) || die "Cannot open file"; # open the fil +e or say can't open file # Read it in +to an array print " what are you looking for? "; $a = <STDIN>; chomp $a; # get rid of a + new line while (<INFO>){ if($file eq "\n"){ last; } my @matches = grep {/$a/i} <INFO>; # find all +the matches print "The following matches were found: @matches\n"; # print th +e matches }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pattern matching
by runrig (Abbot) on Dec 01, 2000 at 21:41 UTC | |
|
Re: pattern matching
by mrmick (Curate) on Dec 01, 2000 at 19:48 UTC | |
|
Re: pattern matching
by marvell (Pilgrim) on Dec 01, 2000 at 19:29 UTC |