in reply to Most Annoying Error : Use of uninitialized value in concatenation (.) or string at C:\Perl\O
An easy way to avoid the warning -- and make sure you only insert rows that have the expected amount of actual data -- would be:
You have another symptom of being too trusting: you pass $ARGV[0] to the open statement without checking to see if the user supplied an arg on the command line.my @db_values = split (/,/,$entry); next unless ( @db_values == 7 ); ## add this line $DB->sql("INSERT INTO Files ... ");
In your case (opening a file for input), die would say "No such file or directory" after you get the warning "Use of uninitialized value in open". Oddly enough when I just now tested an open for output with nothing in @ARGV, I got no warning, no error, and no output file -- which makes it a really tricky thing to catch. (That seems like a perl bug, and worthy of a separate thread...)
Anyway, you should always check input (from users or data files) before using it.
update: forgot to mention -- are you sure you want to be using DBI to insert stuff into the database? It's very slow and you have to do all the work yourself (which you have not been doing yet) of checking that the values are appropriate before inserting them. I expect that your database engine (whatever it is) has its own tool or method for inserting data from a file, which will run a lot quicker (and value checks are likely to be built-in); note that you can (and should) use perl to condition data in advance if needed, and to run that tool.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Most Annoying Error : Use of uninitialized value in concatenation (.) or string at C:\Perl\O
by Steve_p (Priest) on Jul 15, 2005 at 17:34 UTC | |
by graff (Chancellor) on Jul 15, 2005 at 19:22 UTC |