I usually code that as:
foreach ( @ar1, $var1, $var2, @ar2 ) { $_ = '' if ! defined $_; }
TMTOWTDI!
The undef values generally don't cause trouble unless you are interpolating
them into a string. Unfortunately, I frequently do that with most
variables, so I generally convert undef to '' for variables receiving values
from any columns that might be NULL.
--
Mac :})
** I normally forward private database questions to the DBI mail lists. **
Give a hobbit a fish and he'll eat fish for a day.
Give a hobbit a ring and he'll eat fish for an age.
----- Original Message -----
From: "Caraway, Michael" <[EMAIL PROTECTED]>
To: "'Sterin, Ilya'" <[EMAIL PROTECTED]>; "Caraway, Michael"
<[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Cc: "DiGiovanni, Jim" <[EMAIL PROTECTED]>
Sent: Wednesday, May 23, 2001 10:39
Subject: RE: Newbie Q. : fetchrow_array.
> I am running Oracle 8.0.5, Perl 5.005_03, DBI 1.14, and DBD Oracle 1.06 on
> Red Hat Linux 6.2 and that is how it works here. If you have a different
> setup, it may work differently.
>
> I have many Perl DBI scripts running against my database, and in every
> instance where a null is returned, the Perl variable is undef. My 'fix'
is:
>
> unless (defined $var) { $var = "" }
>
> It fixed it every time.
>
> -----Original Message-----
> From: Sterin, Ilya [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 23, 2001 10:05 AM
> To: 'Caraway, Michael '; ''[EMAIL PROTECTED]' '; '[EMAIL PROTECTED] '
> Cc: 'DiGiovanni, Jim '
> Subject: RE: Newbie Q. : fetchrow_array.
>
>
> Well, that's not true. This is not C/C++ and an undefined value will
print
> nothing with no error.
>
> Ilya Sterin
>
> -----Original Message-----
> From: Caraway, Michael
> To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
> Cc: DiGiovanni, Jim
> Sent: 05/23/2001 6:39 AM
> Subject: RE: Newbie Q. : fetchrow_array.
>
> When a row of data is returned, some of the fields may be null. If so,
> trying to print the field results in an error because you are accessing
> an
> undefined value. Check the values first (if defined) before using them.
>
> Michael
>
> -----Original Message-----
> From: Krung Saengpole [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 23, 2001 3:47 AM
> To: [EMAIL PROTECTED]
> Subject: Newbie Q. : fetchrow_array.
>
>
> Hello all,
>
> I just start to learn dbi and have a problem with it. I use dbi to
> connect
> to Access database and fetch the data to array 'til end of file.
> But it only showed 2 lines of data and error took place. No error code
> or
> message shown the reason why. My code is:
>
> use DBI;
>
> $dbh = DBI->connect('dbi:ODBC:myDSN', '','');
> $sth = $dbh->prepare("Select * From TotalLevel");
> $sth->execute();
> while (@data = $sth->fetchrow_array) {
> foreach (@data){
> print "$_ \t";
> }
> print "\n";
> }
> $sth->finish;
> $dbh->disconnect;
>
> Any help would be appreciated. Thank you in advance.
>
> Krung
>
>
> Confidentiality Note: This e-mail, and any attachment to it, contains
> privileged and confidential information intended only for the use of the
> individual(s) or entity named on the e-mail. If the reader of this
> e-mail
> is not the intended recipient, or the employee or agent responsible for
> delivering it to the intended recipient, you are hereby notified that
> reading this e-mail is strictly prohibited. If you have received this
> e-mail in error, please immediately return it to the sender and delete
> it
> from your system.
>
> This e-mail and any attachment(s) are believed to be free from virus.
> However it is the responsibility of the recipient to ensure that they
> are
> virus free. We do not accept any liability for any loss or damage
> arising
> in any way from the receipt, opening or use of this e-mail and any
> attachment(s). Thank You.
>
>
> Confidentiality Note: This e-mail, and any attachment to it, contains
> privileged and confidential information intended only for the use of the
> individual(s) or entity named on the e-mail. If the reader of this e-mail
> is not the intended recipient, or the employee or agent responsible for
> delivering it to the intended recipient, you are hereby notified that
> reading this e-mail is strictly prohibited. If you have received this
> e-mail in error, please immediately return it to the sender and delete it
> from your system.
>
> This e-mail and any attachment(s) are believed to be free from virus.
> However it is the responsibility of the recipient to ensure that they are
> virus free. We do not accept any liability for any loss or damage arising
> in any way from the receipt, opening or use of this e-mail and any
> attachment(s). Thank You.