Re: [OT] Warnings from code when using perl-dbi
- From: hjp@xxxxxxxxx (Peter J. Holzer)
- Date: Thu, 16 Aug 2007 13:35:51 +0200
On 2007-08-16 18:30:52 +0800, Ow Mun Heng wrote:
On Thu, 2007-08-16 at 11:50 +0200, Peter J. Holzer wrote:
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.
In SQL, length(NULL) is NULL, not 0. In Perl length(undef) is 0, but you
get a warning.
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?
Nothing. There is nothing to do in this case.
} else {
print "\"$first[$counter]\"";
}
You could invert the test to avoid the empty if:
if (defined($first[$counter]))
{
print "\"$first[$counter]\"";
}
[...]
Of course the whole loop can be written quite a bit shorter (and more
"perlish"):
print join(q{,}, map { defined $_ ? qq{"$_"} : q{} } @first), "\n";
hp
--
_ | Peter J. Holzer | If I wanted to be "academically correct",
|_|_) | Sysadmin WSR | I'd be programming in Java.
| | | hjp@xxxxxxxxx | I don't, and I'm not.
__/ | http://www.hjp.at/ | -- Jesse Erlbaum on dbi-users
Attachment:
pgpFwcExLcZuc.pgp
Description: PGP signature
- References:
- [OT] Warnings from code when using perl-dbi
- From: Ow Mun Heng
- Re: [OT] Warnings from code when using perl-dbi
- From: Peter J. Holzer
- Re: [OT] Warnings from code when using perl-dbi
- From: Ow Mun Heng
- [OT] Warnings from code when using perl-dbi
- Prev by Date: DBI returned timestamp does not include seconds
- Next by Date: Re: Another set of DBI docs
- Previous by thread: Re: [OT] Warnings from code when using perl-dbi
- Next by thread: Connecting to Progress Database
- Index(es):
Relevant Pages
|
|