in reply to How to Process Log file
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 ismy $LOGFILE = "iptraf.log"; open(LOGFILE, $LOGFILE) or die("Could not open log file."); foreach my $line (<LOGFILE>) { #chomp($line); }
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.
|
|---|