perl functions and arrays

Hi,

First I will tell my objective of this function (function one).

I have a table for ex:

id passwd name
-- ------ -----

1 fdhgfs werwer
2 fsdfs sdfsdf
3 sdfs sdfsdf
4 fdsfs dssdf
. . .
.
.
.

The id, passwd and name are the arguments for another function say two.

The function one should store the values of the table and it should be passed as arguments to function two, one row at a time.

The both functions must be independent also.

code:

#!/usr/bin/perl
use DBI;

my $var_id;
sub read_db
{

$dbh = DBI -> connect('DBI:Oracle:mercury','student','learn') || die "unable to connect:$DBI::errstr";

#Here I am counting the number rows the table has, so that i can use that for the limit in the for loop

my $count = qq/select count(id) from rules_test/;
my $sth = $dbh->prepare($count);
$sth->execute();
print "$count";

#Here I am getting values of id

my $var_id = qq/SELECT id FROM rules_test/;
my $sth = $dbh->prepare($var_id);
$sth->execute();

while(@data = $sth-> fetchrow_array())

{

my $var_id = data[1];

for ($i=1; $i=$count; $i++)

{

my $sql = qq/SELECT id, passwd, name FROM rules_test where id = data[i]/;

my $sth = $dbh->prepare($sql);
$sth->execute();
my ($col1, $col2, $col3);

$sth->bind_col(1, \$col1);
$sth->bind_col(2, \$col2);
$sth->bind_col(3, \$col3);
while ($sth->fetch) {
$sth->bind_col(3, \$col3);

while ($sth->fetch) {
print "$col1, $col2, $col3\n";

}
}
}
&read_db($var_id);
}

-------code ends--------------

I think I am lost somewhere.....

Could u guys help me in this?

this is the code i wrote before...

but this is an hard coded one...
Instead of hard coding i wanna the function to fetch that for each record of the id field and store it.

\#!/usr/bin/perl
use DBI;

$var_id = "3";
 sub read_db
\{


$dbh = DBI -> connect\('DBI:Oracle:mercury','student','learn'\) || die "unable to connect:$DBI::errstr";


my $sql = qq/SELECT id, passwd, name FROM rules_test where id  = '$var_id '/;   
my $sth = $dbh->prepare\($sql\);        
$sth->execute\(\);                      
my \($col1, $col2, $col3\);


$sth->bind_col\(1, \\$col1\);
$sth->bind_col\(2, \\$col2\);
$sth->bind_col\(3, \\$col3\);
while \($sth->fetch\) \{ 
    print "$col1, $col2, $col3\\n";
\#print "\\n\\n\\n$col1\\n";

\}
\}
&read\_quality\_db\($var_rule\);

thanks

mercury