On Sat, 13 Apr 2013 21:20:30 +0530
Asad <asad.hasan2...@gmail.com> wrote:

>        I have completed O'Reily first book Learning Perl . Started
> writing small perl programs . However I basically do log file
> analysis , hence was thinking is there any perl code around in any of
> the book or if anyone already developed for the following
> requirement :
> 
> Nowadays I manually read the log files to read the errors which are
> either fatal or warning or ignorable . The purpose is I want to
> develop a web page as in I upload this log file and it searches for
> those keywords (fatal or warning or ignorable) and if found those
> keywords display the 10line before it and after it .
> 
> Please share your thoughts. Unable to start .

At what point are you stuck?

Learning Perl should cover the basics you're describing - opening a
file, looping over it line by line, and checking if a line matches a
regular expression should all be quite easy for you.

(I would recommend working this out as a standalone script you run
locally to start with, and worry about the handling file uploads etc
afterwards, rather than trying to tackle it all at once.)

When you're looping over the file, you can easily keep the last 5 lines
in a "buffer" (use an array, push() a line to it each time, and if it
contains > 5 lines, shift() the oldest off the front); when you find a
line that matches your pattern, print those five lines, then the line
you're processing, then the next 5.

What you're talking about sounds a lot like "grep -C5 filename",
though - possible wheel re-invention :)

Cheers

Dave P


-- 
David Precious ("bigpresh") <dav...@preshweb.co.uk>
http://www.preshweb.co.uk/     www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedin    www.preshweb.co.uk/facebook
www.preshweb.co.uk/cpan        www.preshweb.co.uk/github



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to