On Thu, 2007-08-16 at 11:50 +0200, Peter J. Holzer wrote:
> On 2007-08-16 16:38:02 +0800, Ow Mun Heng wrote:
> > Sorry, this isn't really a perl-dbi issue per-se. but I don't know where
> > else to post this issue. I can't find a "Perl" mail-list. There's loads
> > of list, but no perl-general.
>
> The newsgroup comp.lang.perl.misc is probably the best place to discuss
> general perl questions.
No nntp for me to use. best would be mail list
> You really want to know whether $first[$counter] is undef, not whether
> it has a length == 0 here, so you should test for that:
>
> if (!defined($first[$counter]))
That worked.. I was thinking of checking the length because if there the
data is NULL, then length should be 0 and not undef.
> an alternative is to use
>
> no warnings 'undefined';
>
> in the smallest enclosing block. But that is only useful if you want to
> treat undefined values exactly like empty strings, which isn't the case
> here.
NULL != Empty string.. Right.
Here's the altered one, for brewity..
my @first;
while ( @first = $sth->fetchrow_array )
{
my $count = @first;
my $first = @first;
for ($counter = 0; $counter < $count; $counter = $counter + 1)
{
if ($counter == $count-1)
{
if (!defined($first[$counter]))
{
# WHAT DO I PUT HERE?
} else {
print "\"$first[$counter]\"";
}
} else {
if (!defined($first[$counter]))
{
print ",";
} else {
print "\"$first[$counter]\",";
}
}
}
print ("\n");
}
}