Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: unique visitors from html logfile

by mbethke (Hermit)
on Nov 17, 2012 at 07:03 UTC ( #1004284=note: print w/replies, xml ) Need Help??


in reply to unique visitors from html logfile

There are actually only two little things that keep your code from working:
  1. You declare (and unnecessarily clear) %ips inside the loop.
  2. You assign the line contents to $ips{$site} instead of incrementing a counter there. $ips{$site}++ is fine---if the element doesn't exist, it will read as undef which in numeric context is a zero.

I don't know how big your logs are but another thing you could do is improve that regexp: be as specific as you can about each field. At the very least that means specifying a non-blank character where you need one/ On my machine, parsing a typical log line with your version takes about 5.2Ás; if I change $w to /(\S+?)/, it's just about 0.9Ás. Adding an /o flag to only have it interpolate and compile the regexp once brings it down to 0.35Ás. I'm not sure why the difference is so big as there's not that much backtracking╣ but anyway it helps. I didn't benchmark whether it makes a speed difference but the assignment is much shorter to write as follows:

my ($site, $logName, $fullName, $date, $time, $gmt, $req, $file, $prot +o, $status, $length) = $line =~ /^$w .../o;

╣ Using $w = "(.+)" which really backtracks lot takes a whopping 185Ás per line.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004284]
help
Chatterbox?
[hippo]: yum update perl
[hippo]: Other package managers are available
LanX wouldn't update system Perl!
[Discipulus]: prathap keerthipati might be it is better to install an alternative Perl instead and do not touch the system one
[LanX]: see perlbrew for alternative Perl installations
[marto]: unless you know exactly what you're doing an often saner option is to simply build another Perl rather than replace the system one

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (16)
As of 2017-03-23 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (285 votes). Check out past polls.