[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [coldsync-hackers] Perl question



Hi Brian,

On Mon, Apr 01, 2002 at 04:31:16AM +0000, Brian Johnson wrote:
> If I just check them against each other directly, I get
> 'uninitialized variables' errors when the field is not used
> 
> There's got to be an easier way to do this since there are
> about 20 pairs of fields to check in the addressbook app

Use a function for this:

sub string_equal() {
   my $s1=shift;
   my $s2=shift;

   return 1 if (!defined($s1) and !defined($s2));
   return 1 if ((defined($s1) and ($s1 eq '')) and !defined($s2));
   return 1 if ((defined($s2) and ($s2 eq '')) and !defined($s1));
   return 1 if ((defined($s2) and defined($s1)) and ($s1 eq $s2));
   return 0;
}

Then call this function with a pair of variables, that might not
be initialized. If you don't like that multiple exit programming
style, you can also write one big if-statement instead.

Note: This handles undefined and empty strings identically, which
   might not be desireable, if you map "undef" to NULL in SQL/C
   and empty strings to real empty strings, but I use it together
   with an md5sum array.


HTH, Regards

Ingo Oeser
-- 
Science is what we can tell a computer. Art is everything else. --- D.E.Knuth
     >>>   4. Chemnitzer Linux-Tag - 09.+10. Maerz 2002 <<<
              http://www.tu-chemnitz.de/linux/tag/

-- 
This message was sent through the coldsync-hackers mailing list.  To remove
yourself from this mailing list, send a message to majordomo@thedotin.net
with the words "unsubscribe coldsync-hackers" in the message body.  For more
information on Coldsync, send mail to coldsync-hackers-owner@thedotin.net.