develooper Front page | perl.dbi.users | Postings from February 2001

Re: Handeling undef data.

Thread Previous | Thread Next
From:
Michelle Gerfort
Date:
February 22, 2001 05:45
Subject:
Re: Handeling undef data.
Message ID:
3A9517F5.4B514CEC@teligent.se

I don't know. But doesn't eval then evaluate the whole @row?

It seems to me that @row could look like this:
(value1, value2, undef, value3, value4, undef) or something like that.

I then want to print:
value1    value2    undefined value in row   value3    value4   undefined
value in row

But instead I get

value1    value2    undefined value in row  Use of uninitialized value at
/home/www/docs/cgi-bin/CCDB_P/maintrep2.cgi line 137.   value3    value4
undefined value in row   Use of uninitialized value at
/home/www/docs/cgi-bin/CCDB_P/maintrep2.cgi line 137.

And that's just a little more than I wanted to know. }: )

/Michelle


djberge@uswest.com wrote:

> Never tried it, but would wrapping the "fetchrow_array" in
> an 'eval' work?
>
> eval{ @row = $sth->fetchrow_array );
> if($EVAL_ERROR){ # Do whatever }
>
> -----Original Message-----
> From: Michelle Gerfort [mailto:michelle.gerfort@teligent.se]
> Sent: Thursday, February 22, 2001 7:13 AM
> To: DBI-users
> Subject: Handeling undef data.
>
> i there!
>
> I'm having a problem when using fetchrow_array().
>
> The area of the code where the problem is, you find below.
>
> while (@row = $sth->fetchrow_array() ) {
> $len = @row;
> for ($i = 0; $i < $len; $i++) {
>     if ($row[$i] ne ""){
>  print $row[$i] . "\t";
>     }
>     else{
>  print "undefined value in row\t";
>     }
> }
>
> I've read and understand that the fetchrow_array() returns undef when a
> value from the database is NULL. With the code above I can identify that
>
> a value is NULL and print out the line "undefined value in row". So far
> so good.
>
> My problem is that I not only get the line "undefined value in row"
> printed, but I also get this:
> Use of uninitialized value at
> /home/www/docs/cgi-bin/CCDB_P/maintrep2.cgi line 137.
>
> I wonder how I can get rid of these lines and what causes this print. Is
>
> there a good way to take care of such undefined values, that I've missed
>
> reading about?
>
> (I do have O'REILY "Programming the Perl DBI)
>
> Thank you in advance
> Michelle Gerfort


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About