Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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

by been42 (Curate)
on Sep 17, 2004 at 03:50 UTC ( #391654=note: print w/replies, xml ) Need Help??

in reply to grab 'n' lines from a file above and below a /match/

I know that I'm showing up a little bit late to the party, but wouldn't Tie::File work for this?

use strict; use Tie::File; # some variables get set up here since we're using strict (wink) tie @lines, 'Tie::File', 'GWSvc.log', memory=>$some_small_number; for ($i=0; $i<$#lines; $i++) { if (/c9391b56-b174-441b-921c-7d63/) { for ($j=$i-5; $j <= $i+5; $j++) { print $lines[$j]; } } }

I'm sure there are a million ways to make it look cleaner, but I'm also very sleepy right now. This seems like it would solve the problem, though. I'm really a big fan of Tie::File after having been 'corrected' on my non-usage of it not too long ago. Now I find uses for it everywhere.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://391654]
[Corion]: TCLion: I'm not aware of a better way than manually building the hash, as all strptime incarnations I know have nasty edge cases
[davido]: And remember; time is hard. :) As soon as you think, I've got this, you'll discover that time is harder than that. :)
[1nickt]: TCLion are you parsing the dates with DateTime or another tool?
[1nickt]: I note DateTime::Format:: Flexible, announced immediately below this box in the CPAN feed

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2017-03-23 14:42 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (287 votes). Check out past polls.