2 messages in com.mysql.lists.perlman page error?| From | Sent On | Attachments |
|---|---|---|
| Scott D. Webster | 27 Dec 2001 14:05 | |
| Jochen Wiedmann | 28 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.
-- Scott D. Webster, RHCE mailto:SWeb...@EtcServices.com Etc Services http://www.EtcServices.com Voice: 201.439.1900 Fax: 201.439.0366 Pager: 800.379.2402 Linux, UNIX, Internet Technology, & Open Source Software Consulting




