By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,852 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,852 IT Pros & Developers. It's quick & easy.

perl functions and arrays

P: 8
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 records of the table and it should be passed as arguments to function two, one record at a time.

The both functions must be independent also.


Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/perl
  3. use DBI;
  4.  
  5. my $var_id;
  6.  sub read_db
  7. {
  8.  
  9.  
  10.  
  11.  
  12. $dbh = DBI -> connect('DBI:Oracle:mercury','student','learn') || die "unable to connect:$DBI::errstr";
  13.  
  14. #Here I am counting the number rows the table has, so that i can use that for the limit in the for loop
  15.  
  16. my $count = qq/select count(id) from rules_test/;
  17. my $sth = $dbh->prepare($count);        
  18. $sth->execute();
  19. print "$count";
  20.  
  21. #Here I am getting values of  id
  22.  
  23. my $var_id = qq/SELECT id FROM rules_test/;
  24. my $sth = $dbh->prepare($var_id);        
  25. $sth->execute();
  26.  
  27.  
  28.  
  29. while(@data = $sth-> fetchrow_array())
  30.  
  31. {
  32.  
  33. my $var_id = data[1];
  34.  
  35.  
  36. for ($i=1; $i=$count; $i++)
  37.  
  38. {
  39.  
  40.  
  41. my $sql = qq/SELECT id, passwd, name FROM rules_test where id  = data[i]/;
  42.  
  43. my $sth = $dbh->prepare($sql);        
  44. $sth->execute();                      
  45. my ($col1, $col2, $col3);
  46.  
  47.  
  48. $sth->bind_col(1, \$col1);
  49. $sth->bind_col(2, \$col2);
  50. $sth->bind_col(3, \$col3);
  51. while ($sth->fetch) { 
  52. $sth->bind_col(3, \$col3);
  53.  
  54. while ($sth->fetch) { 
  55.     print "$col1, $col2, $col3\n";
  56.  
  57.  
  58. }
  59. }
  60. }
  61. &read_db($var_id);
  62. }
  63.  

I think I am lost somewhere.....

Could u guys help me in this?
Jan 17 '08 #1
Share this Question
Share on Google+
6 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
For your reference, here is a guide on how to use this sites code tags. These are not optional. We require that you surround your code in these each time code is posted into the forums.

Regards,

MODERATOR
Jan 17 '08 #2

numberwhun
Expert Mod 2.5K+
P: 3,503
I just noticed that you re-posted this thread, yet again, as a duplicate. I have deleted that thread and left this one in place. Please do not go creating duplicate threads. If you have an update to the code you posted, reply to this thread and post your updated code.

Regards,

MODERATOR
Jan 17 '08 #3

numberwhun
Expert Mod 2.5K+
P: 3,503
That is now TWICE that you have re-created the SAME thread in this forum. This is your last warning. Please DO NOT create duplicate threads in the forums. If you re-create this thread again, I will ban you for 1 week.

Regards,

MODERATOR
Jan 17 '08 #4

P: 8
That is now TWICE that you have re-created the SAME thread in this forum. This is your last warning. Please DO NOT create duplicate threads in the forums. If you re-create this thread again, I will ban you for 1 week.

Regards,

MODERATOR
sorry abt tat.... i found my thread missing ... so i thought i accidently deleted the thread.. i jus read the rules of the forum...

thanks
mercury
Jan 17 '08 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
sorry abt tat.... i found my thread missing ... so i thought i accidently deleted the thread.. i jus read the rules of the forum...

thanks
mercury
You are correct, the second thread you posted was missing because it was a duplicate of this first thread.

Regards,

MODERATOR
Jan 17 '08 #6

eWish
Expert 100+
P: 971
Once you add the strict and warnings pragmas you will see more clearly some of your issues. Also, the special variable @_ holds the incoming data. Your subroutine is not using that variable, so the data you are sending it not doing any good. Checkout perlvar for more information.

--Kevin
Jan 17 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.