in reply to Find a specific word in a text file
It is the custom in our Monastery that you show the code you have written to solve your problem or otherwise show us that you have at least tried to solve the problem. The Monastery is not a "Solve-my-homework-for-me"-service!
That being said, did you try to use the m// function? It tries to match a regular expression against another string and returns true if the match succeed:
Some explanation:use strict; my $text='Try to find the hidden string here!'; if ($text=~m/\bhidden\b/) { print "We found the hidden string!\n"; } else { print "No match, sorry.\n"; }
Update: as japhy and ysth told me, the marker for the word boundary is \b. I have updated the example program above. What do we learn from such errors: Never try to do any serious work before your second cup of strong tea!
CountZero
"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Find a specific word in a text file
by japhy (Canon) on Sep 09, 2004 at 07:05 UTC | |
|
Re^2: Find a specific word in a text file
by algonquin (Sexton) on Sep 11, 2004 at 10:57 UTC | |
|
Re^2: Find a specific word in a text file
by algonquin (Sexton) on Sep 09, 2004 at 08:17 UTC |