Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: undef and empty variables

by sundialsvc4 (Abbot)
on Jan 19, 2011 at 18:16 UTC ( [id://883183]=note: print w/replies, xml ) Need Help??


in reply to undef and empty variables

It is my understanding that undef always becomes NULL, and that the handling of “an empty string” may vary.   (Database drivers tend to try to second-guess that situation, and the outcome is typically not that bad ...)

Nevertheless, bear in mind that, in an array, undef is “a value.”   The slot is occupied, although the value in that slot may be undef.

Replies are listed 'Best First'.
Re^2: undef and empty variables
by sundialsvc4 (Abbot) on Jan 20, 2011 at 15:11 UTC

    Thinking further about exactly how I would write this ... I would pass a hashref containing the parameter values, to a sub that would perform the query.   The SQL string would use placeholders, and the corresponding array of parameter-values would contain expressions that pulled keys from the hashref ... by name.   Any non-existent key would produce undef automagically.

    My sub would also contain error checks.   If the hashref was supposed to contain certain keys and perhaps to have non-empty values for those keys, my routine would expressly check for this and would croak if something was not right. (Thus, “the fact that the program did not croak” tells me positively that the error condition I was testing for does not exist ... “therefore, the bug must be somewhere else.”)   The code would go straight into production with those error-checks in place.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://883183]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found