Baz has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
I'd like to process my access_log which has the following format -
68.1.62.74 - - [19/Mar/2003:22:34:22 -0500] "GET /rhcp/tabs/b.cgi?" "M +ozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" 24.52.81.64 - - [19/Mar/2003:22:36:14 -0500] "GET /ff/tabs/index.cgi H +TTP/1.1" 200 4210 "Mozilla/4.0 (compatible; MSIE 6.0; MSN 2.5; Windo +ws 98)"
I'd like to be able to display how many hits a particular page gets per day.
I know that fseek is required when handling large files in C. How might I go about reading a large file using perl.
Thanks
Barry.

Replies are listed 'Best First'.
Re: Processing a log file
by mpeppler (Vicar) on Dec 31, 2003 at 19:04 UTC
    There's nothing special about reading a large file in perl (or in C, for that matter). You just open it, and read it a line (or block) at a time:
    open(IN, "access_log") || die "Can't open file: $!"; while(<IN>) { ... process the line ... } close(IN);
    Of course here it's the ...process the line... bit that does all the interesting stuff, like parsing the access_log line to extract the information that interests you.

    I haven't checked, but I wouldn't be surprised if there was already a module on CPAN which does access_log parsing.

    Michael

Re: Processing a log file
by dominix (Deacon) on Jan 01, 2004 at 05:44 UTC
Re: Processing a log file
by naChoZ (Curate) on Jan 01, 2004 at 14:16 UTC

    In the interest of not reinventing the wheel, there is also a fine tool that generates graphs and everything. Have a look at webalizer.

    --
    Diplomacy is the art of saying "Nice doggie" until you can find a rock.
    naChoZ