Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8826845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:14:36+00:00 2026-06-14T07:14:36+00:00

I am working on an assignment where i need to parse a log file

  • 0

I am working on an assignment where i need to parse a log file and create a website based on said log file. one of the requirements is that i count the number of hits that happened on yesterdays, im lost when it comes to this ive attached my code and the log file im working with hoping that someone can offer some advice, thanks

#!/usr/bin/perl
use strict;
use warnings;
use Time::Piece;
use Time::Seconds qw(ONE_DAY);


my $yesterday = localtime() - ONE_DAY();
print $yesterday;




open(LOGFILE,"<", "access.log")or die"Could not open log file.";
my $yesterdayHits=0;

my $totalhits=0;
my $webPage='log.html';

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 ("<TABLE BORDER=1 CELLPADDING=10 width='500px'>");

foreach my $line (<LOGFILE>) {
    $totalhits++;
    my $w = "(.+?)";
    $line =~ m/^$w $w $w \[$w:$w $w\] "$w $w $w" $w $w/;

    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;
    #if($line =~ m/$yesterday/){$yesterdayHits++}


print WEBPAGE ("<Tr><TD>$site</TD><TD>$line</TD></Tr>\n\n");


}



close(LOGFILE);
print WEBPAGE ("<h2>Total hits: $totalhits</h2>");
print WEBPAGE ("<h3>Hits Yesterday: $yesterdayHits</h3>");
print WEBPAGE ("</TABLE></P>");
print WEBPAGE ("</BODY></HTML>");
close(WEBPAGE); 

Access log

66.249.65.107 - - [11/Nov/2012:19:33:01 -0400] "GET /support.html HTTP/1.1" 200 11179 
111.111.111.111 - - [11/Nov/2012:19:33:01 -0400] "GET / HTTP/1.1" 200 10801
111.111.111.111 - - [08/Oct/2007:11:17:55 -0400] "GET /style.css HTTP/1.1" 200 3225
123.123.123.123 - - [26/Apr/2000:00:23:48 -0400] "GET /pics/wpaper.gif HTTP/1.0" 200 6248
123.123.123.123 - - [26/Apr/2000:00:23:40 -0400] "GET /asctortf/ HTTP/1.0" 200 8130
123.123.123.123 - - [26/Apr/2000:00:23:48 -0400] "GET /pics/5star2000.gif HTTP/1.0" 200 4005
123.123.123.123 - - [26/Apr/2000:00:23:50 -0400] "GET /pics/5star.gif HTTP/1.0" 200 1031
123.123.123.123 - - [26/Apr/2000:00:23:51 -0400] "GET /pics/a2hlogo.jpg HTTP/1.0" 200 4282
123.123.123.123 - - [26/Apr/2000:00:23:51 -0400] "GET /cgi-bin/newcount?jafsof3&width=4&font=digital&noshow HTTP/1.0" 200 36 
172.16.130.42 - - [26/Apr/2000:00:00:12 -0400] "GET /contacts.html HTTP/1.0" 200 4595 
10.0.1.3 - - [26/Apr/2000:00:17:19 -0400] "GET /news/news.html HTTP/1.0" 200 16716
129.21.109.81 - - [26/Apr/2000:00:16:12 -0400] "GET /download/windows/asctab31.zip HTTP/1.0" 200 1540096
192.168.198.92 - - [22/Dec/2002:23:08:37 -0400] "GET / HTTP/1.1" 200 6394
192.168.198.92 - - [22/Dec/2002:23:08:38 -0400] "GET /images/logo.gif HTTP/1.1" 200 807
192.168.72.177 - - [22/Dec/2002:23:32:14 -0400] "GET /news/sports.html HTTP/1.1" 200 3500 
192.168.72.177 - - [22/Dec/2002:23:32:14 -0400] "GET /favicon.ico HTTP/1.1" 404 1997
192.168.72.177 - - [04/Nov/2012:23:32:15 -0400] "GET /style.css HTTP/1.1" 200 4138
192.168.72.177 - - [22/Dec/2002:23:32:16 -0400] "GET /js/ads.js HTTP/1.1" 200 10229
192.168.72.177 - - [22/Dec/2002:23:32:19 -0400] "GET /search.php HTTP/1.1" 400 1997
127.0.0.1 - - [10/Apr/2007:10:39:11 +0300] "GET / HTTP/1.1" 500 606 
127.0.0.1 - - [10/Apr/2007:10:39:11 +0300] "GET /favicon.ico HTTP/1.1" 200 766 
139.12.0.2 - - [10/Apr/2007:10:40:54 +0300] "GET / HTTP/1.1" 500 612 
139.12.0.2 - - [10/Apr/2007:10:40:54 +0300] "GET /favicon.ico HTTP/1.1" 200 766 
127.0.0.1 - - [10/Apr/2007:10:53:10 +0300] "GET / HTTP/1.1" 500 612
127.0.0.1 - - [10/Apr/2007:10:54:08 +0300] "GET / HTTP/1.0" 200 3700 
127.0.0.1 - - [10/Apr/2007:10:54:08 +0300] "GET /style.css HTTP/1.1" 200 614
127.0.0.1 - - [10/Apr/2007:10:54:08 +0300] "GET /img/pti-round.jpg HTTP/1.1" 200 17524
127.0.0.1 - - [10/Apr/2007:10:54:21 +0300] "GET /unix_sysadmin.html HTTP/1.1" 200 3880
217.0.22.3 - - [04/Nov/2012:10:54:51 +0300] "GET / HTTP/1.1" 200 34 
217.0.22.3 - - [10/Apr/2007:10:54:51 +0300] "GET /favicon.ico HTTP/1.1" 200 11514
217.0.22.3 - - [10/Apr/2007:10:54:53 +0300] "GET /cgi/pti.pl HTTP/1.1" 500 617 
127.0.0.1 - - [10/Apr/2007:10:54:08 +0300] "GET / HTTP/0.9" 200 3700 
217.0.22.3 - - [10/Apr/2007:10:58:27 +0300] "GET / HTTP/1.1" 200 3700 
217.0.22.3 - - [10/Apr/2007:10:58:34 +0300] "GET /unix_sysadmin.html HTTP/1.1" 200 3880 
217.0.22.3 - - [10/Apr/2007:10:58:45 +0300] "GET /talks/Fundamentals/read-excel-file.html HTTP/1.1" 404 311 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:14:38+00:00Added an answer on June 14, 2026 at 7:14 am
    use POSIX;
    
    $yesterday = strftime("%d/%b/%Y",localtime(time()-86400));
    

    $yesterday now contains yesterday’s date in the logfile’s format (e.g. “11/Nov/2012”). You can filter lines by checking $line =~ /$yesterday/;

    http://perldoc.perl.org/POSIX.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on this assignment. I need to create a temporary stack without
As part of an assignment I need to create a shipping program that checks
I am working on an assignment where I need to do calculations with large
I've been working on this assignment, where I need to read in records and
I'm working on my assignment of PHP course. The problem that I don't understand
I am working on an assignment for networking where we are supposed to create
I am working on an assignment where one of the problems asks to derive
I am working on an assignment that deals with reading data from a text
I am currently in an introductory c++ class and am working assignment that sorts
I am working on an assignment that requires me to reimplement all of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.