Greetings Monks,

I'm a bit of a klutz with regular expressions, but I've taken a shot at making this script which parses log entries for a Pure Ftpd server I run. I'm looking for ways to improve it's efficiency and readability. The log entries are separated by carraige returns and the elements by single spaces.

#!/usr/bin/perl use strict; use warnings; my $data = 'Jul 30 19:39:06 server pure-ftpd: (user@68.158.32.189) [NOTICE] /home/shows//Genesis/Genesis 1978-06-24 FLAC/genesis1978-06-24-prefm-d1t04.flac downloaded (71074015 bytes, 60.83KB/sec) Jul 30 19:39:23 server pure-ftpd: (user@68.17.66.125) [NOTICE] /home/shows//Simon and Garfunkel/Simon and Garfunkel 2003-10-16/SG2003-10-16-d2t03.shn downloaded (2075533 bytes, 115.25KB/sec)'; my @lines = split "\n", $data; foreach my $line (@lines) { $line =~ m/^(\w+)\s(\d+)\s(\S+)\s\w+\s\D+\s\D(\w+) \x40(\d+\W\d+\W\d+\W\d+)\D\s\S+\s(.*) \s+\w+\s+\S?(\d+)\s\w+\S\s(\d+\W\d+)/; print "Month is: $1\n"; print "Day is: $2\n"; print "Time is: $3\n"; print "User is: $4\n"; print "IP is: $5\n"; print "File is: $6\n"; print "Size is : $7\n"; print "Speed is : $8\n"; } 1;

In reply to Pure Ftpd log regex by redhotpenguin

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.