in reply to Duplicity Check Help!
undef is not-equal to “an empty string.”
Therefore, each of your if statements evalues to true, and the variable gets incremented several times.
Use the defined() function to check for a NULL field value, which comes across as undef.
Be sure not to use an “empty string” value in a text column, unless “an empty string” is a plausible, non-NULL possibility in your application. (Unlikely.)
As for myself, I am not a fan of using the || alternate_value syntax. Although you might think of it as being a check for NULL, it is in fact a check for anything that evaluates to a false value according to whatever rules Perl may have. Which is why you see stuff like this in my code:
There are many ways to write it, of course, but the idea is clear: for an arbitrarily-long list of field names, if any of the returned values is undef a specific value is substituted for them. (Since this is, of course, being applied against the in-memory (not tied) hash returned by DBI::fetchrow_hashref, it does not modify the database in any way.)do { $$rec{$_} = "foo" unless defined($$rec{$_}) } foreach qw(FIELD1 FIELD2 FIELD3);
This uses the foreach modifier exactly as described in perldoc perlsyn.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Duplicity Check Help!
by Anonymous Monk on Dec 02, 2010 at 14:57 UTC |