Melodious Monks,
As a good perl coder should almost always do, I always start my programs with '-w' and 'use strict', which ensures that I'm easily caught when I make stupid mistakes! Unfortunately, I beat my head against the wall the other day for about 30 minutes trying to debug a DBI query, before realizing that I had a typo in my execute statement.
Much to my amazement, there was no warning thrown telling me something to the effect of 'use of uninitialized value in hash element' thrown when calling code such as the following:
#!/usr/local/bin/perl -w
use strict;
use DBI;
my $user = $ARGV[0];
my $pass = $ARGV[1];
my $dbh = DBI->connect('DBI:mysql:database=test;host=localhost',
$user, $pass,
{
RaiseError => 1,
AutoCommit => 1,
PrintError => 1,
}
);
my $create_sql =<<SQL;
CREATE TEMPORARY TABLE IF NOT EXISTS test_situation (id int, data
+int)
SQL
$dbh->do($create_sql);
my $sql = "SELECT * FROM test_situation WHERE id = ?";
my $sth = $dbh->prepare($sql);
## Notice array does not even contain element that I reference:
my $href = {
foo => 1,
bar => 2,
baz => 3,
};
$sth->execute($href->{'id'}); ## Shouldn't this throw a warning?
Why?!? It was very frustrating when I realized that the problem was a mis-casing of one of the hash keys that I was using, and it was something that warnings would always catch.
Any clues?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.