in reply to Substituting '--' for Nulls

Why would you expect it to print a dash? You never even try to substitute a dash.

Use something like:

print map {defined () ? $_ : "--"} @results; print "\n";
as the body of your while loop.

And with the latest development version, you can write that as

print map {$_ // "--"} @results; print "\n";
Abigail

Replies are listed 'Best First'.
Re: Re: Substituting '--' for Nulls
by virtualsue (Vicar) on Aug 13, 2002 at 12:24 UTC
    I believe the main test here needs to be for "", not for definedness. DBI is going to give him an array, and some of the values in it may be empty strings, if I understand the problem correctly. The empty strings are what needs to be replaced. I think this variation will do the job:
    my @results_tmp = map {($_ ne "") ? "$_" : "--"} @results; print join(",", @results_tmp),"\n";
    For those who aren't comfortable with map, this is about the same as:
    my @results_tmp = @results; ($_ eq "") && ($_ = "--") for @results_tmp; print join(",", @results_tmp),"\n";
      Could you give us an example where Perl issues the warning "Use of uninitialized value" where the value is actually defined and equal to ""?

      Abigail

      The error "use of uninitialized value" described in the root node is a good indication that DBI was, in fact, properly handing back undefined values that were then being used as strings.
Re: Re: Substituting '--' for Nulls
by johnirl (Monk) on Aug 13, 2002 at 10:26 UTC
    Thanks Abigail
    I have tried a couple of subroutines to do it but they didn't work so I ommitted them from the code. Didn't want to embarass myself :-)

    j o h n i r l .

    Sum day soon I'Il lern how 2 spelI (nad tYpe)