Although you have a couple ways described here I decided to munge it myself. (After all it's perl and theres always more than one way! )

This code uses an array of Hashes to represent the records. and the Lefthand identifier ( From: Date: etc ) is dynamically used for the hash keys. This is IMHO more flexable. Heres the code:
#!/usr/bin/perl use strict ; use warnings ; use Data::Dumper ; my @records ; my $count = 0 ; while (<DATA>) { next if ( /^\n/ ) ; # skip newlines if (/^--/) # new record { $count++ ; next ; } my ( $field, @words ) = split ; # get the 2 needed fields $field =~ s/://g ; # drop the ":" my $data = join " ", @words ; # make a string chomp $data ; # remove the newline $records[$count]{$field} = $data ; } print Dumper(\@records); # easy way to unfold the structure __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 ----------------------------------
you can now unfold the structure by looping through @records :
foreach my $record (@records) { # $record is now a ref to the Hash it contianed # print a field from the record print "\nNew Record\n" ; print "FROM: $$record{From}, \n" ; # or loop through each key for current record foreach my $key (sort keys %$record ) { print "$key => $$record{$key} \n" ; } }
Hope it helps !


In reply to Re: virus log parser by yodabjorn
in thread 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.