my $LOGFILE = "iptraf.log"; open(LOGFILE, $LOGFILE) or die("Could not open log file."); foreach my $line (<LOGFILE>) { #chomp($line); }
Depending on the actual structure of your script you may even use Perl's own automagic <>. Whatwever, it is generally recommended to avoid slurping files all at once (and if doing so, possibly to use a suitable module, e.g. File::Slurp1), unless of course one has to do so. A for loop will slurp in all at once. In any case Perl5's idiomatic cycle for iterating over the lines of a file is
while (<$handle>) { # ... }
I understand their is a bit of work in this script, but some heads up on how to structure this array for creating and writing. Or should i directly begin inserting data in the database rather than reading it into an associate array?
This is up to you, and hopefully someone more experienced with DBses than I am will give you more insightful advice. In any case, split is your friend.

Update: on a second reading, the format of the log file is not simple enough that a plain split would suffice. Fortunately holli has shown you how to do it with an extensive code sample at Re: How to Process Log file.


1 I'm not really sure about the latter point. But many people recommend doing so.


In reply to Re: How to Process Log file by blazar
in thread How to Process Log file by Anonymous Monk

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.