473,387 Members | 1,582 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,387 software developers and data experts.

PERL and DBI and WHILE LOOP

4
Hi,

I have to code this part in perl and using DBI.

1. I have a SQL select query which fetches some rows based on order.
2. I have to fetch each row at a time, once i fetch the first row i process the fields and some response is returned.
3. now I have to fetch the next row again and do the step 2.

This whole process should be in a while loop since this perl script will be running everytime based on some sleep command and fetched data and process.

Please help, need this as soon as possible.

Here is my sample code
Expand|Select|Wrap|Line Numbers
  1. $signal = 0;
  2. while (!$signal)
  3. {
  4. $sql = getsqlquery();
  5. $sth = $dbh->prepare($sql);
  6. eval
  7. {
  8. $sth->execute;
  9. };
  10.  
  11. if (@$)
  12. {
  13. addToLogFile($followerName, 'ERROR', "Fetching rows from query execute command failed." . $dbh->errstr() . "Trying to connect again in 10 secs");
  14. sleep(30);
  15. $signal = 0; 
  16. }
  17.  
  18. if ($sth->rows == -1)
  19. {
  20. addToLogFile($followerName, 'INFO', "No Commands in the query table. Sleeping for 10 seconds to recheck the table.");
  21. sleep 10;
  22. $signal = 0;
  23. }
  24. while (my @data = $sth->fetchrow_array())
  25. {
  26. $signal = &processCommand(@data);
  27. }
  28. }
  29. sub processCommand()
  30. {
  31. do some sql queryies ;
  32.  
  33. return 0;
  34.  
  35.  
  36. }
  37.  
Feb 24 '10 #1
2 2396
numberwhun
3,509 Expert Mod 2GB
First, please use code tags around code you place in the forums.

Second, I read your post, but do you have a question?

Regards,

Jeff
Feb 25 '10 #2
sha37
4
the above code does not work. if i have 40 records in the database, for each record it runs 40 times and its runs 40x40 times.
Feb 25 '10 #3

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

Similar topics

41
by: Xah Lee | last post by:
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of...
4
by: Ted Hopp | last post by:
Why does the following program print "Undefined!"? Shouldn't the subroutine leave the value of $x alone? (I can understand it clobbering $_, but $x?) #!/usr/bin/perl -w use strict; sub...
9
by: Martin Foster | last post by:
Hi. I would like to be able to mimic the unix tool 'uniq' within a Perl script. I have a file with entries that look like this 4 10 21 37 58 83 111 145 184 226...
1
by: roadbai | last post by:
Hi all, This is the first time to post question here, hopefully experts of perl here can give me a hand, to be honest, I am kind of new to perl, and I am struggling with the "Out of memory" issue I...
5
by: Karyn Williams | last post by:
I am new to Pyton. I am trying to modify and understand a script someone else wrote. I am trying to make sense of the following code snippet. I know line 7 would be best coded with regex. I first...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
0
by: chris.santry | last post by:
I'm trying to convert the following Perl code to VB.net ################################################################### # Calculates the checksum for the message # # In: The string # Out:...
4
by: jonniethecodeprince | last post by:
#This is a program from dummies.com $TheDB = 'edata.txt'; # Open the database file but quit if it doesn't exist open(INDB, $TheDB) or die "The database $TheDB could " . "not be found.\n"; ...
6
by: Paulchen | last post by:
Hello, I have found a perl script and need to "translate" this to PHP. I try to do it step by step and the first part of it is this function (the whole script is found at...
11
by: doraima29 | last post by:
Hi, I am a newbie at PERL and really wanted to understand how server-side programming really works and operates since I use at the workplace. I use ASP and wanted to learn more about server-side...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.