So I have a simple script that rolls through a text file and loads anything it recognizes into a database like so:
if (/^\s*(\S+)\s+(\S+)\s+(.+\S)\s*$/) { $dbh->do('replace into reference_code values (?,?,?)',undef,$1,$ +2,$3) or die $dbh->errstr ;
The die may seem excessive, but I didn't expect any problems. Turns out I was wrong. The second and third column are marked as 'not null' in the database. This code died on the first line of the text file, claiming that the third column was null. I assumed I screwed up the regex, so added 1,2, and 3 to the die just to verify like so:
if (/^\s*(\S+)\s+(\S+)\s+(.+\S)\s*$/) { $dbh->do('replace into reference_code values (?,?,?)',undef,$1,$ +2,$3) or die "[$1] [$2] [$3] [". $dbh->errstr ."]";
and while it died with the same error, all three columns had a fair amount of data. Thinking something may be going wrong with the error string, I decided to print 1,2,and 3 just before each execution, just to make sure it was trying to insert what I thought it was:
if (/^\s*(\S+)\s+(\S+)\s+(.+\S)\s*$/) { print "[$1] [$2] [$3]\n"; $dbh->do('replace into reference_code values (?,?,?)',undef,$1,$ +2,$3) or die "[$1] [$2] [$3] [". $dbh->errstr ."]";
This ran to completion without error. Wtf? If I comment out the print, it once again errors right off the bat saying the third column is null, and if I uncomment it again, it runs fine. ??????

In reply to Bitten by the lazy execution bug? by Anonymous Monk

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.