Pauline,

On Fri, Mar 09, 2001 at 12:09:27PM -0500, Price, Pauline wrote:
> Hello,
> 
> I am a recent returnee to the Perl fold.  I last used perl 4 and sybperl.  
> Now several years later I am using the latest perl and DBI.  Obviously
> I am quite new to the current environment.  I have the following code:
> 
> while (my @fetchData = $stBankAccountH->fetchrow_array()) { 
>       if (!($stBankAccountH->err)) { 
> 
>               my $output = join ("|",@fetchData);
>               print OUT "$output\n";
> 
>       } else {
> 
>               return $flag;
> 
>       }

There were several good responses on how to receive the date data formatted
as you wish.  However, I noticed another problem with your code that you 
should be aware of.  The $sth->fetchrow_array() method returns an empty
list if it has already returned the last row of data, or if an error 
occurred while fetching a row of data.

You are checking for the possibility of an error inside of the while loop.
As long as @fetchData contains values, the row was successfully fetched.
If an error occurs, an empty list will be returned (a logical false) and
the while () {... } loop will not be entered.  Therefore the check for an
error should happen after the loop.  Try something like this:

while (my @fetchData = $stBankAccountH->fetchrow_array()) {
  my $output = join ("|",@fetchData);
               print OUT "$output\n";
}

if ($stBankAccountH->err) {
  warn "An error occurred while fetching data: ", 
      $stBankAccountH->errstr;
}
else {
  print "No error occurred while fetching data.\n";
}


-C.

Reply via email to