2 messages in com.mysql.lists.perlman page error?
FromSent OnAttachments
Scott D. Webster27 Dec 2001 14:05 
Jochen Wiedmann28 Dec 2001 08:31 
Subject:man page error?
From:Scott D. Webster (SWeb@EtcServices.com)
Date:12/27/2001 02:05:38 PM
List:com.mysql.lists.perl

m{y,}sql module meisters,

The logic of one of the code examples in the DBD::mysql man page seems to be defective.

Here's how the code looks in the manpage:

" my $sth = $dbh->prepare("SELECT * FROM $table"); if (!$sth) { die "Error:" . $dbh->errstr . "\n"; } if (!$sth->execute) { die "Error:" . $sth->errstr . "\n"; } my $names = $sth->{'NAME'}; my $numFields = $sth->{'NUM_OF_FIELDS'}; for (my $i = 0; $i < $numFields; $i++) { printf("%s%s", $$names[$i], $i ? "," : ""); }"

Here's how I think it should look:

"my $sth = $dbh->prepare("SELECT * FROM $table"); if (!$sth) { die "Error:" . $dbh->errstr . "\n"; } if (!$sth->execute) { die "Error:" . $sth->errstr . "\n"; } my $names = $sth->{'NAME'}; my $numFields = $sth->{'NUM_OF_FIELDS'}; for( $i = $num_fields - 1; $i >= 0; $i--) { printf("%s%s", $$names[$i], $i ? ", " : ""); }"

The difference is in the for() loop. My way makes it add a comma and space after all but the last field name.