I'm working on a script where I'm given a log file and need to print some of its info to an HTML file. One problem I'm having is that at the top of the HTML file, I need to print the start of the log date, which will be the earliest date found in the log. I believe I need to implement this in my while loop but I'm not sure how it will work. Here's my code:

#! /usr/bin/perl # CSC 310 Project # 4 #opening log and html file open (LOG, '<', 'IN-access.log'); open (HTML, '>>', 'OUT-access.html'); #printing header/title/format of html print HTML "<HTML><TITLE>Visitors Log</TITLE><BODY>\n"; print HTML "The log file start date is: date() <BR>\n"; <----HERE +!!! print HTML "There were 11 unique visitors in the logfile.<BR>\n"; print HTML "There were 2 visits yesterday<BR>\n"; print HTML "<TABLE border=1><TR><TD>IP</TD><TD>LOGFILE</TD></TR>\n"; #reading log file and assigning values while ($lines = <LOG>){ ($remoteIP,$rfc,$userID,$dateTime,$timeZone,$requestType,$fileRequ +ested,$requestProtocol,$statusCode,$sizeOfFile) = split ' ', $lines; print HTML "<TR><TD>$remoteIP</TD><TD>$remoteIP $rfc $userID $date +Time $timeZone $requestType $fileRequested $requestProtocol $statusCo +de $sizeOfFile</TD></TR>\n"; }

Just for reference, here is an example of what is found in the log file

66.249.65.107 - - 08/Oct/2007:04:54:20 -0400 "GET /support.html HTTP/1.1" 200 11179

111.111.111.111 - - 05/Oct/2004:15:17:55 -0400 "GET / HTTP/1.1" 200 10801

111.111.111.111 - - 06/Oct/2007:11:17:55 -0400 "GET /style.css HTTP/1.1" 200 3225

Do I need to convert the date somehow so I can compare them? Or can I tell perl to just check certain parts of the variable? All suggestions are welcome.


In reply to How to calculate earliest date from log file by jaffinito34

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.