Im trying to count whenever a thread is done in perl, and print the count. but this is not working. i keep getting either "0" or "1", im trying to add to the count then print the count right after the get request is made.
use strict;
use threads;
use LWP::UserAgent;
our $MAX //= $ARGV[1];
my $list = $ARGV[0];
open my $handle, '<', $list;
chomp(my @array = <$handle>);
close $handle;
my $lines = `cat $list | wc -l`;
my $count = 0;
my @threads;
foreach $_ (@array) {
push @threads, async{
my @chars = ("a".."z");
my $random = join '', map { @chars[rand @chars] } 1 .. 6;
my $ua = LWP::UserAgent->new;
my $url = $_ . '?session=' . $random;
my $response = $ua->get($url);
count++;
print $count;
};
sleep 1 while threads->list( threads::running ) > $MAX;
}
$_->join for @threads;