in reply to push to an array lines matching a pattern, and the lines before and after the matching

Your Perl solution slurps in the entire file, one line per element, copies the entire contents to @_, copies that once more into @n lexical to the sub.

Unix grep doesn't do any of that.

I would not be ashamed to call out to an external program. No need to reinvent the wheel, even if the wheel isn't found on CPAN.

  • Comment on Re: push to an array lines matching a pattern, and the lines before and after the matching

Replies are listed 'Best First'.
Re^2: push to an array lines matching a pattern, and the lines before and after the matching
by gianni (Novice) on Mar 04, 2012 at 17:23 UTC
    Perl grep, that is the slow part... and yes, unix grep is 10 times faster