[Gllug] Forking (Perl)

Luke Hopkins (Broadbean) luke at broadbean.co.uk
Tue Feb 1 13:37:26 UTC 2005


I'm sure this is an easy one for Perl gurus.
Instead of iterating through a foreach loop sequentially, I want to fork
off the sub called, and without waiting for it to return move on to the
next item.

E.g.
	foreach $filename(@listing) {
		# open $filename, use LWP to post data to a remote
server

If I have 60 files, and each one requires 10 seconds to complete the
transaction with the remote server, this will take ~10 minutes to
complete. However I would rather open 60 connections with the remote
server(s), make the transactions and return within ~10 seconds.

In an ideal world data returned by the sub would be available as each
one completes.
So if I call postme($filename,$server) and the sub returns something
like:
return($filename,$success_status);

I could print the results as they come back (I don't think at this stage
they need necessarily be in order, I can manage that later)

Is this a simple use of fork()?

Thanks
Luke

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list