473,411 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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 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
6 1579
numberwhun
3,509 Expert Mod 2GB
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
3,509 Expert Mod 2GB
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
3,509 Expert Mod 2GB
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
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
3,509 Expert Mod 2GB
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
971 Expert 512MB
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

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

Similar topics

7
by: el_roachmeister | last post by:
Is there a good article that explains why php does not support =~ like perl for regex? I am confused by all the different ways one can do regex in php but it would seem supporting =~ would...
5
by: John Smith | last post by:
Can someone point me to an example of how to implement and access the kind of object shown below? Most of the examples if found are an object that contains one other object. I need to create an...
2
by: kelly | last post by:
Hi, I don't have a code to show you, what I need are references or algorithms so that I'm in a right track. By the way, thanks for introducing me the array or arrays. Now I can continue my...
5
KevinADC
by: KevinADC | last post by:
Introduction This discussion of the sort function is targeted at beginners to perl coding. More experienced perl coders will find nothing new or useful. Sorting lists or arrays is a very common...
8
by: Palindrom | last post by:
Hi everyone ! I'd like to apologize in advance for my bad english, it's not my mother tongue... My girlfriend (who is a newbie in Python, but knows Perl quite well) asked me this morning why...
223
by: Pilcrow | last post by:
Given that UNIX, including networking, is almost entirely coded in C, how come so many things are almost impossible in ordinary C? Examples: Network and internet access, access to UNIX...
0
by: Michael C | last post by:
"John Brock" <jbrock@panix.comwrote in message news:gg56ab$qsn$1@reader1.panix.com... You really need to stop trying to write perl code in dot net and VBA. Arrays are hard to resize for a good...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.