A co-worker is learning Perl through self study. He's borrowed my Llama book for a start. As part of the learning I've agreed to provide him with "real world" exercises.

Do the following exercises for analysing *nix log files seem reasonable to you? He seems to be having trouble with them. He does know about split and join and the basics of array and hash use. A few hundred lines of messages was snipped and dropped into the directory he's using for the exercises.

Problem #1: Read the log file messages. Print a list of: Count TimeStamp I'm looking for the number of log messages per hour of the day. S +omething like
144 Apr 10 04:00 280 Apr 10 05:00 Problem #2 Read the log file messages instead of counting the number of messag +es per hour, count the number of instances for each message. Something like 2 syslogd 1.4.1: restart (remote reception). 189 ntpd[3216]: synchronized to 192.168.1.15, stratum 3 1880 last message repeated 9 times Problem #3 Modify solution to problem #2 so that "last message repeated X time +s" adds to the count of the last message Problem #4 Modify solution to problem #3 to ignore the PID Meaning: ntpd[3216]: synchronized to 192.168.1.15, stratum 3 will report as ntpd: synchronized to 192.168.1.15, stratum 3 Problem #5 Modify solution to problem #4 to report on activity per hour Apr 10 04:00 - XXXXX xxxx ntpd: synchronized to 192.168.1.15, stratum 3 xxxx syslogd 1.4.1: restart (remote reception). replacing xxxx with the acutal numbers

Be Appropriate && Follow Your Curiosity

In reply to Log parsing exercises for Perl beginner - reasonable? by mikeraz

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.