Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

PerlbeginnercliAI generated

Log File Parser and Summary Reporter

Build a Perl script that reads a web server's access log (Apache or Nginx) and prints a clear summary: the IP addresses making the most requests, how many requests got each status code (200, 404, 500 and so on), and the most requested pages. It's a classic Perl task that shows why the language became popular for working with text: you'll learn regular expressions to pull fields out of each line, hashes to count things, sorting a hash by its values, formatting output with printf, reading command-line options with Getopt::Long, and checking your results against a sample log.

Estimate
~6h
Steps
5
Completed by
0
Proposed by
codeseed.app

Perl core modules

Project roadmap

  1. 01

    Parse log lines with a regex

    ~1.5h

    Get a sample access log (from your own server or a public sample) in the common or combined format. Write a regular expression that captures the IP, the time, the method, the path, the status code and the size. Print the fields from the first 5 lines to check them. Lines that don't match are counted, not fatal. Done when: the fields from the sample lines are printed correctly.

  2. 02

    Count with hashes

    ~1h

    Read the log line by line and count requests per IP, per status code and per path (removing the query string after ?) in three hashes, plus the total number of requests and the bytes sent. Done when: the total matches the number of valid lines in the file.

  3. 03

    Sort and print the report

    ~1.5h

    Sort each hash by count, highest first (with sort { $h{$b} <=> $h{$a} } keys %h), and print the top N of each with printf in aligned columns, with each item's share of the total. Print status codes in numeric order with a label for each class (2xx success, 4xx client errors and so on). Done when: the report is aligned and easy to read.

  4. 04

    Add command-line options

    ~1h

    Use Getopt::Long to accept the log file (or read standard input when none is given), --top N (default 10) and --status CODE to count only requests with a given status. Print a usage message with --help or for invalid options, and a clear error when the file can't be opened. Done when: every option works, and mistakes print helpful messages.

  5. 05

    Check the results

    ~1h

    Create a small test log with known counts (including a malformed line and paths with query strings) and write tests with Test::More that check the counts and the top entries. Compare a few numbers on a real log with grep and wc. Done when: prove passes, and the spot checks match.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~6h · 5 steps

Tech stack

Perl core modules