Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Once again I am struck by how true it is, that a good programmer should always follow up on warnings.

I'm writing a DBI program with a CGI interface. The program reads information from the database, performs some transformations, and puts the result into an HTML table. Easy.

But my database has a number of NULL values. This didn't cause any problems in the HTML output, it just made Perl generate a hundreds of annoying warnings about the "use of an uninitialized value". (When using "warnings", of course.) I'll admit that I always used to hate this warning -- after all, I didn't really care if the values were defined or not, as long as the output looked okay.

I initially intended to turn off the warnings, at least in a small block around my string-handling code. But there was this little nagging voice in my head that said, "Make your program run clean under 'use warnings' and 'use strict'". I'm pretty sure that I got this voice from Perl Monks.

And so I spent thirty minutes finding all of the places where the data could possibly be NULL, and I made sure they were defined, like this:

$string = "" unless defined($string);
This got rid of most of the warnings, but there were more. Whoops, I missed a few NULLs. Thirty minutes later I was sure that I had tracked them all down, so I ran the program again. Now, my hundreds of warnings were down to about five.

So I spent another thirty minutes trying to find a place in my code where I could still be getting undefined values. And what did I find? A very real problem with my database. There were NULLS in fields where there shouldn't have been -- where I was absolutely positive that there weren't any. I hadn't even thought to double-check it before.

I've fixed my database, and the program runs clean now. And I am very glad that I didn't turn off warnings, even for one seemingly innocent line of code.

buckaduck


In reply to Always Follow Up on Warnings by buckaduck

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2024-04-18 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found