Chris McMahon wrote:
>
> > This script:
> > *******************************
> > use warnings;
> > use Win32:ODBC;
> > my $db = new Win32::ODBC("TheDB");
> >
> > $db->Sql("SELECT * FROM dbo.foo");
> > $db->FetchRow();
> > my @values = $db->Data;
> > print @values;
> > *************************************
> > Yields two "Use of uninitialized value in print..." error
> > messages before it prints @values.
> >
> > If anyone could explain why (and maybe how to get rid of
> > them), I'd appreciate it...
>
> Sorry to reply to my own post, but it seems that NULL values in the
> tables themselves cause the "uninitialized value" warnings.
> This seems like strange behavior-- if anyone can suggest a way to
> shut them down without losing -w, please make a suggestion...

Hi Chris.

The usual way of representing a NULL database value in Perl is as
'undef' which is the value a scalar takes before it has been
assigned.

Change your code to:

  my @values = map { defined() ? $_ : 'NULL' } $db->Data;
  print @values;

and the warning will go away. Beware, though, that you must
change the 'NULL' strings back to undef if you need to write
the data back to the database.

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to