in reply to DBI and Hash

What are acceptable null values to your database? You need to determine that before you start transforming fields that are not present (in any given line of the log file).

Could you, for example, get away with:

foreach my $temp (@dbfields) { $sqlinsert{$temp} = "DUMMYDATA" unless ($sqlinsert{$temp});

Of course, if your DB fields are data-type constrained, you'll have to do your substitution on a per-key basis -- to ensure that INT fields get a dummy INT value, and so on ( ...and it'll get really tricky if there's a BOOL field. :-) )

OTOH, who controls the format of the log files? If you do, perhaps you'll find it easier to tackle that end of your puzzle, supplying an appropriate dummy value to each empty field.

Update: recast first question.

Replies are listed 'Best First'.
Re^2: DBI and Hash
by elmic11111 (Novice) on Feb 13, 2012 at 23:28 UTC
    Well I feel dumb, I went and re-ran the code to get the error to paste here and didn't get an error. Now I need to go figure out why. Should have pasted it here the first time.

      Just for what it's worth, the default value for an inserted row is a NULL value. (Unless overridden, so I guess I should have said "default default value.") Assume a table named test of columns foo, bar, baz:

      INSERT INTO test (foo, bar) VALUES('fred', 'barney');

      Now, the column baz should be NULL. In other words, if you want to insert a NULL into a database, you can just omit it from the list of columns.

      BTW, your foreach sets the numeric value zero and the empty string to NULL, too. I doubt you want that. You should be using unless exists $sqlinsert{$temp} instead.

      Oh, and dummy values suck.