in reply to multithreading sample

Hi,

Here you have an example:

#!/usr/bin/perl -w $|++; use strict; use threads; use threads::shared; # Flag variable we use to stop the 2nd thread my $complete : shared = 0; # Create the thread my $thread = threads->create(\&dothis); # Code of main thread goes here sleep 5; # Change the flag variable so the thread ends $complete = 1; # Join the threads together $thread->join(); # End of the program exit; sub dothis { until($complete) { print "#"; sleep 1; } print "\n"; }

Take a look at threads.

But you can use fork and sending a kill signal to the child instead, I think it would be faster and more efficient.

For more complicated solution think about Event, Event::Lib or POE.

Update: This code is a example of threads, but of course for a simple stats of a file download is not necessary... as stated before. I supossed that you wanted a simple example to see how threads work in Perl.

Regards,

|fire| at irc.freenode.net