Hi fellow Monks!

I'm trying to go through some large (2.8 GB) log files from IIS. Each line looks like:

80.129.152.192 - - [09/Dec/2001:00:23:26 0100] "GET /informationRoot/foo/bar/foo.gif HTTP/1.1" 200 631 I want to find out the number of unique visits for each log file. My code takes the IP from each line and counts it and adds it to a list (if it's not allready there, in case it just skips the line). This is not a good solution and it's extremely time consuming.

Here's the code anyway:

if ($ARGV[0]) { go(); } else { die "\nUsage: stats.pl [filename] [filename} ...\n\n"; } sub go() { foreach $filename (@ARGV) { $file = $filename; open (FILE, $file); $i = 0; my @list=""; while (<FILE>) { /(.*)\s-\s-/; $ip = $1; if (notInList($ip)) { $i++; addToList($ip); } } print "\nVisits for $file is $i\n"; } } # Subfunctions sub addToList($ip) { push @list,$ip; } sub notInList($ip) { foreach $tmpip (@list) { if ($tmpip eq $ip) { return 0; last;} } return 1; }

Anyone have suggestions for improving this?

Edit dws code tags</code>


In reply to Unique visits - Webserver log parser by ciryon

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.