in reply to Find a specific word in a text file

I see you are new to our Monastery: so let me bid you welcome and may your search for more Perl-wisdom be fruitful.

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:

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"; }
Some explanation:Now for the other part of your question: What other word do you need to grab? Do you know what that word will be beforehand or is it just any word before or after the first word you found? Why do you want to analyse it character-by-character? That seems a bit artificial.

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
    You mean \b, not \w.
    _____________________________________________________
    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re^2: Find a specific word in a text file
by algonquin (Sexton) on Sep 11, 2004 at 10:57 UTC
    Thank you for your input countzero, I appreciate it.
Re^2: Find a specific word in a text file
by algonquin (Sexton) on Sep 09, 2004 at 08:17 UTC
    Thanks CZ, I found "Today's ID" via while (<>) { if (/Today's ID/) { print $_; } now I need to move some blank spaces and 4 letters forward to grab five digits. (sorry, I loose the format of my message when I click to release)