"Peter R. Wood - Lists" wrote:

> The query in perl dbi:
> 
> --snip--
> my $assignment_query =
>   "SELECT grade " .
>   "FROM student_assignment";
> my $sth = $dbh->prepare($assignment_query);
> $sth->execute();
> my @assignments;
> while ( my $grade = $sth->fetchrow() )
> {
>   push(@grades,$grade);
> }
> print "@grades";
> --snip--
> 
> This generates an array containing
> 22 20 20 22 25 15 17 16
> 
> The 0 value is missing.
> 
> Is there any way to have zero values not thrown away?

Yes. Your while condition is the problem. The 0 value is interpreted as
false in this context and your while loop exits. Use a list notation
instead, because a list containing the value 0 is not false:

 my $grade;
 while ( ($grade) = $sth->fetchrow() ) {
   ...
 }

Joern

-- 
Joern Reder -- Software Development,  dimedis GmbH, 50672 Koeln
               http://www.dimedis.de/ http://spirit.dimedis.de/
supporting:    http://www.zyn.de/ http://www.netcologne.de/~nc-joernre/
CPAN:          http://www.perl.com/CPAN/modules/by-module/CIPP/JRED/

Reply via email to