Hi everyone, I thought $sth->fetchrow_array would do the trick but its not. I am using mysql on linux and I have a query:
SELECT hostname FROM tblHost WHERE status="started";
which returns a list of hostnames. I though the fetchrow_array would
return a array of hostnames but it does not seem to. It seems to only
return the first hostname unless I put it in a while loop.
Is there a way that I can grab every hostname from the table into an
array so that I can run soemthing like a foreach on it??
Right now I have:
<code>
#!/usr/bin/perl
use strict;
use DBI;
my $uptime;
my $db = "testdb";
my $user = "root";
my $passwd =" ";
open (UPTIME, "/proc/uptime");
while (my $line=<UPTIME>) {
chomp $line;
($uptime,undef)=split(/ /,$line);
}
close UPTIME;
if ($uptime < 240) {
my $dbh = DBI->connect('DBI:mysql:$db', "$user", "$passwd") or die
"Cannot connect to database: $!";
my $sth = $dbh->prepare (qq{SELECT hostname FROM tblHost where
status="started"});
$sth->execute();
while ( my @unfinished = $sth->fetchrow_array) {
print @unfinished,"\n";
}
}else{
print "this box has been up fo a while\n";
}
</code>
Which prints out everything fine. But it doesn't seem like it a true
array. I can't just put
my @unfinished = $sth->fetchrow_array;
print @unfinished,"\n";
and have it return the array of hosts
I'd rather just have an array of hostnames instaed of while bla bal
bla.
Does anyone see what I am doing wrong????
As always, thanks for the help
--chad
--
Chad Kellerman
Jr. Systems Administrator
Alabanza Inc
410-234-3305
signature.asc
Description: This is a digitally signed message part
