Just a few things from skimming over your code:

Use Placeholders!.

Instead of

my $sql = "INSERT INTO ERRORS (TSTAMP,CMND_ID,ALERT_ID,SEND_ID,DESTIN +ATION,MESSAGE,STATE,SVR_HOST) VALUES (\'$tstamp\',\'$cmnd_id\',\'$ale +rt_id\',\'$send +_id\',\'$destination\',\'$message\',\'$state\',\'$svr_host\')\;\n"; my $statement = $db_handle->prepare($sql) or die "Couldn't prepare query '$sql': $DBI::errst +r\n"; $statement->execute() or die "Couldn't execute query '$sql': $DBI::errst +r\n";
write
my $sql = qq{"INSERT INTO ERRORS (TSTAMP,CMND_ID,ALERT_ID,SEND_ID,DEST +INATION,MESSAGE,STATE,SVR_HOST) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?); my $statement = $dbh->prepare($sql); $statement->execute($tstamp, $cmnd_id, ...);

Also make sure to pass the {RaiseError =>1} argument to DBI->connect, then you don't need the custom error handlers.

Even more important: you can prepare the statements once outside the loop, and then call execute them inside the loops as many times as you need them. That way you'll gain much performance (if you have many iterations).

Instead of

if($line =~ /^SendCleared~(.*)~(.*)~(.*)~(.*)~(.*)~(.*)/){ my $tstamp = $1; my $cmnd_id = $2; my $alert_id = $3; my $send_id = $4; my $state = $5; my $svr_host = $6;
you can first check if the line starts with SendCleared and then use
my ($tstamp, $cmnd_id, ...) = split m/~/, $line;

There are actually even better ways to handle the dispatch with a hash: you can store these sql queries in a has with keys SendOffDuty, AlertCmd and so on, and then do something like that:

# assume %q contains the quries my ($query, @args) = split $line, '~'; $q{$query}->execute(@args); # assuming the log files are well formed

In reply to Re: Need Critique (Good or Bad) by moritz
in thread Need Critique (Good or Bad) by onegative

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.