in reply to find words around a word in a file.
For example if the word is proceeded by 10 empty lines, should the code find the last word before the 10 empty lines as context?
Does isn't count as one word? or two? or something else?
A very simplistic search could use a regex, and only succeed if the word is not the first or last in a line:
while (<$FILE>) { if (/(\S+)\s+going\s+(\S+)/) { print "before: '$1'; after: '$2'\n"; } }
for some very crude definition of "word".
For a more robust solution you could use App::Ack to give you some lines of context before and after the found word, and then extract the words you need.
If you need a more robust detection of word boundaries, read up on text segementation.
|
|---|