> Howdy,
> 
> I have a question from one of our developers that's been bugging me and I
> can't find an answer.  Given this v1.37 DBI code fragement:
> 
> while ( my ($projectno,$description,$dateclosed) = $sth->fetchrow_array )
> {
>       print "$projectno";
>       print "$description";
>       print "$dateclosed";
>       print "\n";
> }
> 
> ...I keep getting a "Use of uninitialized value in string" message on the
> print of the $dateclosed variable, whenever the corresponding Oracle DB
> column is NULL.  And you've already figured out that the program is run
> with
> "-W".  When the "-W" is dropped, no message.

(Sorry about the previous blank message.)

Here are two common ways to handle this issue:

Turn off warnings lexically:

while (my($id, $value) = $sth->fetchrow_array()) {
  local $^W;

  print "$id = $value\n";
}


Convert undef to empty string:

while (my($id, $value) = $sth->fetchrow_array()) {
  foreach ($id, $value) {
    $_ ||= '';
  }

  print "$id = $value\n";
}

HTH,
Ronald


Reply via email to