I'm trying to make threaded Net::Telnet program.
I want all "input_log" to be written to one file.
So I tried to give an IOScalar FileHandle to "input_log", then output real file
later.
IOScalar works fine, threads works fine.
But together dosen't work.
Here is sample script.
Any suggestions appreciated.
# works fine without threads
use strict;
use FileHandle;
my @result;
for (my $i = 0; $i < 10; $i++) {
my $fh = new FileHandle \($result[$i]), '>:scalar';
$fh->print("test$i");
$fh->close();
}
for (@result) {
print $_, "\n";
}
-----
# no output with threads
use strict;
use FileHandle;
use threads ('yield',
'stack_size' => 64*4096,
'exit' => 'threads_only',
'stringify');
my @result;
my @thr;
for (my $i = 0; $i < 10; $i++) {
my $fh = new FileHandle \($result[$i]), '>:scalar';
$thr[$i] = threads->create(sub{$_[0]->print($_[1]);$_[0]->close()},
$fh,
"test$i");
}
for (@thr) {my $dummy = $_->join();}
for (@result) {
print $_, "\n";
}
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/