So, with a few comments from some of the monks here, I've made some simplifications. Thanks especially to crazyinsomniac for suggesting Tie::File. I had read about it before, but using it didn't even occur to me.
#!perl -wT #config variables my $logfile = q(D:\httpd\Apache\logs\error.log); my $domain = ""; my $path = ""; my $expires = ""; my $cookiename = "veloglastline"; ########################################### # # A very simple error_log viewer CGI script for Apache # more instructions will be provided later. # Error lines are wrapped with Text::Wrap # Each time the script is loaded, it tries to set a cookie # containing the last line read in the error log. # Each load of the script accesses the cookie and only # displays unread lines. # # useage: # http://host/path/velog.cgi will show the lines # in the error log you haven't seen yet. # http://host/path/velog.cgi?all=234 will show all # the lines in the error log use strict; use CGI; use Text::Wrap; use Tie::File; my $q = CGI->new(); my $lastline; my @filelines; my @unread; my $cookie; $cookie = $q->cookie($cookiename) || 0; if($cookie =~ m/^(\d*)$/) {$lastline = $1;} else{$lastline = 0;} $lastline = 0 if(defined($q->param("all"))); tie (@filelines, 'Tie::File', $logfile, autochomp => 0) || die "unexpected error opening $logfile: $!"; @unread = @filelines[$lastline .. $#filelines]; @unread = ("No new entries found") if($#unread == 0); $cookie = $q->cookie({-name => $cookiename,-value => $#filelines, -domain => $domain, -expires => $expires, -path => $path }); print $q->header(-type => "text/plain", -cookie => $cookie), wrap("", "", @unread);

In reply to Re: Simple Apache Error Log Viewer by coolmichael
in thread Simple Apache Error Log Viewer by coolmichael

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.