koti688 has asked for the wisdom of the Perl Monks concerning the following question:

I have a array named @events, which consists of a certain number of events.

for example @events = (putdata,getdata,processdata).
in this conteext i need to create 3 threads.

where the elements of @ events are seperate functions. i need to creat as many threads as the number elemnets of @ events array. How to create threads for the element count of array at a time and push to @ threads.

Please help , any thing is helpful in this regard.

Replies are listed 'Best First'.
Re: Regd Threads creation
by Corion (Patriarch) on Apr 02, 2009 at 13:46 UTC

    How about using a loop to create the threads?

Re: Regd Threads creation
by BrowserUk (Patriarch) on Apr 02, 2009 at 14:43 UTC

    Try

    #! perl -sw use strict; use 5.010; use threads; sub putData{ say( "PutData: $_" ), sleep 1 for 1 .. 10 } sub getData{ say( "GetData: $_" ), sleep 1 for 1 .. 10 } sub prcData{ say( "PrcData: $_" ), sleep 1 for 1 .. 10 } my @events = qw[ putData getData prcData ]; my @threads = map async( \&{$_} ), @events; $_->join for @threads;

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.