Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: grab 'n' lines from a file above and below a /match/

by mrpeabody (Friar)
on Sep 20, 2004 at 03:07 UTC ( [id://392274]=note: print w/replies, xml ) Need Help??


in reply to Re^2: grab 'n' lines from a file above and below a /match/
in thread grab 'n' lines from a file above and below a /match/

It's actually slower and more memory intensive than any of the other solutions. Tie::File internally keeps a list of byte offsets for all the lines, and it needs lot of additional overhead that is supposed to optimize writes which you never make any use of.
Oops. Guessed wrong, then.

Your code also doesn't get the edge cases right: if there's a match within less than $context lines of the previous, it will be missed.
That was intentional, and it depends on your definition of "missed". That hit will be printed with the context of the previous hit. Changing the behavior would just require removing the line:
$i += $context;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://392274]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-19 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found