<?xml version="1.0" encoding="windows-1252"?>
<node id="178995" title="Re: virus log parser" created="2002-07-02 16:44:33" updated="2005-08-15 01:35:30">
<type id="11">
note</type>
<author id="80543">
Rhose</author>
<data>
<field name="doctext">
How about collecting the information, then printing the record when you get to one of the '-----' lines? (This assumes all records -- even the last one -- end with a '-----' line.)
&lt;p&gt;
The following code reads from __DATA__ and writes its (tab delimited) records to the screen; you would probably want to open your log file for processing (open(LF,"$logFile")), and write to a results file (open(OF,"&gt;$outputFile")).
&lt;p&gt;
&lt;p&gt;
&lt;code&gt;
#!/usr/bin/perl -w
use strict;

my $gCurRec;

foreach(qw(name to file action virus))
{
  $gCurRec-&gt;{$_}='';
}

while(&lt;DATA&gt;)
{
  $gCurRec-&gt;{name}=$1   if (/^From:\s*(.+?)\s*$/);
  $gCurRec-&gt;{to}=$1     if (/^To:\s*(.+?)\s*$/);
  $gCurRec-&gt;{file}=$1   if (/^File:\s*(.+?)\s*$/);
  $gCurRec-&gt;{action}=$1 if (/^Action:\s*(.+?)\s*$/);
  $gCurRec-&gt;{virus}=$1  if (/^Virus:\s*(.+?)\s*$/);

  if (/^-----/)
  {
    print $gCurRec-&gt;{name},"\t",
          $gCurRec-&gt;{to},"\t",
          $gCurRec-&gt;{file},"\t",
          $gCurRec-&gt;{action},"\t",
          $gCurRec-&gt;{virus},"\n";

    foreach(qw(name to file action virus))
    {
      $gCurRec-&gt;{$_}='';
    }

  }
}


__DATA__
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
----------------------------------
&lt;/code&gt;
&lt;p&gt;
&lt;p&gt;
&lt;b&gt;Comment:&lt;/b&gt;
One other thing I found I like is opening files with three parameters. For example, instead of:
&lt;p&gt;
open(OF,"&gt;$outputFile") || die;
&lt;p&gt;
I use:
&lt;p&gt;
open(OF,'&gt;',$outputFile) || die;
&lt;p&gt;
I hope this helps! *Smiles*
&lt;p&gt;
&lt;b&gt;Update:&lt;/b&gt;&lt;p&gt;
Now that I have re-read my code, I should have made 
&lt;p&gt;qw(name to file action virus)&lt;p&gt;
a constant so it was defined but one place, and should have made the field separator a constant as well. This would simplify changes to the code. (Not that it is critical on such a small program, but it is a good practice... well, for me at least.)</field>
<field name="root_node">
178983</field>
<field name="parent_node">
178983</field>
</data>
</node>
