in reply to Re: Regex: Matching around a word(s)
in thread Regex: Matching around a word(s)
Using modules is always easier than doing things yourself,
Only if there is a module that does exactly what you want to do. Maybe.
If there isn't, picking a module with a name vaguely related to the problem description and trying to bend it to the cause is pointless.
Achieving what you describe--printing the target word and N words either side--is easy using a regex and does have the overhead of creating huge arrays just to stick em all back to gether for output. It is a bread and butter text processing task and exactly what the much lauded, highly prized, Perl-jewel-in-it's-crown regex engine is designed for.
However, resolving the issues of almagamating multiple, closely consecetive matches into single snippets is equally problematic whether done with a regex or your "subarray" solution. (BTW.It should @array[ n .. m ] for a slice).
|
|---|