Home: Perl Programming Help: Advanced:
Signal or While loop


Mar 2, 2010, 10:02 AM

Views: 2891
Signal or While loop

Hi Perl Gurus,

Let me explain what i am looking for.

I have a perl file say (db.pl). This file has a function call getqueryresults().

This getqueryresult does some sql select operation and returns first row of the table.

I have another file called child.pl. This file has a function called


require db.pl;




my $records = getqueryresult();


$records is processed etc etc....

updates to the tables.



now i want the next row to be fetched from db.pl getqueryresults() and again call processchild function. My question is how to do this process.

How can i loop the &processchildfunction in the second line to do the process for each and every child.

What is the best approach? infinite while loop or signals or anything else.

Thanks in Advance.

Sha P


Mar 3, 2010, 5:09 AM

Views: 2873
Re: [sha37] Signal or While loop

What makes your posting unclear to me is that you *describe* that you want to use the result of getqueryresult() for calling processchild(), but this is not reflected in the code example you gave.

Also, you did not mention whether the interface of getqueryresult() is already fixed, or whether you are free to change it.

Basically, you could either have getqueryresult return a list of all childs and then iterate over the list, or you can write getqueryresult in a way that it accepts a code block, which it invokes for every child. I would do the latter if the number of childs is possibly large (and you don't need to store them anyway), and the former approach if the number of childs is small (less than 1000 or so, depending on how much data is associated with each child).