in reply to Finding word either side of a word match
If you insist on creating your index manually, here is what you could do: in the while loop create a list of all found words, and then iterate over all of them again:
# assuming you stored all matches in @words my %word_context; for (1 .. $#words-1){ push @{$word_context{$words[$_]}, [$words[$_ - 1], $words[$_ + 1]]; }
Though it might be better to store context and line number in the same data structure.
You also have to think about the first and the last word, which are special in that they don't have two words of context each. What do you want to do with them?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding word either side of a word match
by Quicksilver (Scribe) on Mar 03, 2008 at 14:44 UTC | |
by moritz (Cardinal) on Mar 03, 2008 at 14:51 UTC | |
by Quicksilver (Scribe) on Mar 03, 2008 at 15:43 UTC | |
by moritz (Cardinal) on Mar 04, 2008 at 08:08 UTC |