I'm a perl-novice... trying to expand my perl knowledge
beyond system administration. I have an anti-virus log file that I would like to eventually put into a mysql database; but I'm having problems parsing it. The log file is a large flat file with "----" lines as record seperators. Here's an example...

From: pminich@foo.com
To: esquared@foofoo.com
File: value.scr
Action: The uncleanable file is deleted.
Virus: WORM_KLEZ.H
----------------------------------
Date: 06/30/2002 00:01:21
From: mef@mememe.com
To: inet@microsoft.com
File: Nr.pif
Action: The uncleanable file is deleted.
Virus: WORM_KLEZ.H
----------------------------------
...
...

I'm trying to place each record on one line (for a sql load). The list screams multi-dimensional array with hash references. But those weren't covered in "Learning Perl" and I'm having difficulties applying examples in "The Perl Cookbook". I know to set the input field seperator to $/='---' to seperate my records, but then what? I'm not sure what to do w/ each record or how to parse it beyond that. I'm currently building a non-multi-dimensional approach with simple RE conditionals...

open(LF,"$logFile") || die "Can't open $logFile: $!\n"; open(OF,">$outputFile") || die; while ($line=<LF>) { chomp($line); if ($line =~ /^Date:\s+(\S+)\s(\S+)/) { $date=$1 . " " . $2; } if ($line=~ /^From:\s+(\S+)/) { $from=$1; } if ($line=~ /^To:\s+\S+/) { # Some "To: lines have multipe ", " # delimited addresses my ($crap, @to);<br> ($crap, @to)=split(/\s+/,$line); print OF "$date\t$from\t@to\n"; } } close(LF); close(OF);

... which is limited to simple if/then statments (the curse of predicate logic classes) and bad regular expressions. I'm really not sure what to do. I can pull my vars here, but each record is a line. Plus it doesn't give me the functionality I really need (I will eventually need to manipulate some of these fields). I was thinking of adding something like (from the Cook Book):

for $x (1 .. 10) {<br> for $y (1 .. 10) {<br> $LoL[$x][$y] = func($x, $y);<br> }

for each var so I could build my matricies; but then I would leave me with something like $foo[$a][$b][$c][$d][$e]; however, I don't know what I have here -- other than a headache. Any suggestions would be greatly appreciated; including more daily uses for references.-- Phaedo


In reply to virus log parser by phaedo

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.