>From what I can see, you just have the print in the wrong place. Each step of the fetch loop, as it gets the names one by one, you push to the names array, then print the array - so you see it each step of the way. Move the print to outside the loop
-----Original Message----- From: chad kellerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, December 17, 2002 3:37 AM To: [EMAIL PROTECTED] Subject: unexpected results with perl and mysql Ney guys, I am trying to fetch and array form a table and I am not getting the results I thought I would get: I thought it was quote simple but when I print them out....well you'll see? <code> #!/usr/bin/perl use strict; use warnings; use DBI; my( $dbname ) = "BACKUP"; my( $mysqluser ) = "bob"; my( $mysqlpasswd ) = "bobspasswd"; my( $dbh, $sth, $rc, @failedCon, $var, $name, @names ); #these variables will be passed to subroutine in main program. my( $hostId ) = "543"; my( $biggyFlag ) = "0"; my( $hostDirFlag ) = "0"; $dbh = DBI->connect( "DBI:mysql:database=".$dbname, $mysqluser, $mysqlpasswd ) or die "Cannot connect to database: $!"; #first check for failed attempts $sth = $dbh->prepare( qq{ SELECT failedConAttempt FROM tblControl WHERE hostId="$hostId" } ); $sth->execute; $sth->bind_columns( \$var ); while ( $sth->fetch ) { push @failedCon, $var; } print "backup failed to connect to $hostId: $failedCon[0] times.\n"; #grab information if ($failedCon[0] != 0 ) { $sth = $dbh->prepare( q{ SELECT name FROM tblProcess WHERE biggy_flag="$biggyFlag" AND hostId="$hostId" AND hostDirFlag="$hostDirFlag" AND status="In-Progress" OR status="Queued" } ); $sth->execute; $sth->bind_columns( \$name ); while ( $sth->fetch ) { push @names, $name; print "@names\n"; } }else{ $sth = $dbh->prepare( q{ SELECT name FROM tblProcess WHERE biggy_flag="$biggyFlag" AND hostId="$hostId" AND hostDirFlag="$hostDirFlag" } ); $sth->execute; $sth->bind_columns( \$name ); while ( $sth->fetchrow_array ) { push @names, $name; print "@names\n"; } } $rc = $dbh->disconnect; </code> when I run this I get: [root@widowmaker sbin]# perl mysql.pl backup failed to connect to 543: 5 times. alan alan alex alan alex bob alan alex bob cole alan alex bob cole brian alan alex bob cole brian coleman alan alex bob cole brian coleman david alan alex bob cole brian coleman david edward alan alex bob cole brian coleman david edward evilyn THe first print statemnet I get I expect, it came out right. But I just want to print the second array.. Why does it print alan alan alex alan alex bob alan alex bob cole alan alex bob cole brian alan alex bob cole brian coleman alan alex bob cole brian coleman david alan alex bob cole brian coleman david edward alan alex bob cole brian coleman david edward evilyn and not just: alan alex bob cole brian coleman david edward evilyn am I missing something??? Thanks, Chad -- Chad Kellerman Jr. Systems Administrator Alabanza Inc 410-234-3305 Australia Post is committed to providing our customers with excellent service. If we can assist you in any way please either telephone 13 13 18 or visit our website www.auspost.com.au. CAUTION This e-mail and any files transmitted with it are privileged and confidential information intended for the use of the addressee. The confidentiality and/or privilege in this e-mail is not waived, lost or destroyed if it has been transmitted to you in error. If you have received this e-mail in error you must (a) not disseminate, copy or take any action in reliance on it; (b) please notify Australia Post immediately by return e-mail to the sender; and (c) please delete the original e-mail.