I'm trying to count unique ips based on a html log file and print that data to a webpage. i have the log file parsed but i am having trouble figuring out how to only select unique ip addresses to print to the webpage, any advice?

#!/usr/bin/perl use strict; use warnings; use 5.010; use POSIX; my $yesterday = strftime("%d/%b/%Y",localtime(time()-86400)); open(LOGFILE,"<", "access.log")or die"Could not open log file."; my $yesterdayHits=0; my $IPcount=0; my $totalhits=0; my $webPage='log.html'; my $startDate; open(WEBPAGE,">",$webPage); print WEBPAGE ("<HEAD><TITLE>Access Counts</TITLE></HEAD>"); print WEBPAGE ("<BODY>"); print WEBPAGE ("<H1> Today is: ",scalar(localtime), "</H1>"); print WEBPAGE ("<h3>Yesterday was $yesterday</h3>"); print WEBPAGE ("<h3>There are $IPcount unique vistors in the log</h3>" +); print WEBPAGE ("<TABLE BORDER=1 CELLPADDING=10 width='500px'>"); print WEBPAGE ("<Tr><td>IP</td><TD>LOGFILE</TD></Tr>\n\n"); foreach my $line (<LOGFILE>) { my %ips=(); $totalhits++; my $w = "(.+?)"; $line =~ m/^$w $w $w \[$w:$w $w\] "$w $w $w" $w $w$/; my @sort=$line; my $site = $1; my $logName = $2; my $fullName = $3; my $date = $4; my $time = $5; my $gmt = $6; my $req = $7; my $file = $8; my $proto = $9; my $status = $10; my $length = $11; $ips{$site} = $line; #print %ips; #foreach my $key ( sort keys %ips ) { # print $key, " => ", $ips{$key}, "\n"; #} my ($day,$month,$year)=split"\/",$date; my %dates = ( 'Jan' => '01', 'Feb' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12', ); print WEBPAGE ("<Tr><td>$site</td><TD>$line</TD></Tr>\n\n") } close(LOGFILE); #print WEBPAGE ("<h2>Start Date is $startDate</h2>"); print WEBPAGE ("<h2>Total hits: $totalhits</h2>"); print WEBPAGE ("<h3>Hits Yesterday: $yesterdayHits</h3>"); print WEBPAGE ("</TABLE></P>"); print WEBPAGE ("</BODY></HTML>"); close(WEBPAGE);

In reply to unique visitors from html logfile by Anonymous Monk

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.