Hi iizuka!
On Tuesday 23 Mar 2010 09:53:54 [email protected] wrote:
> 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.
>
A few notes:
1. There's no such thing as IOScalar. Maybe you mean writing to an in-memory
buffer.
2. Don't use threads in Perl. They cause too many problems.
3. Don't use the FileHandle module. It is deprecated. Look at lexical
filehandles and IO::Handle instead.
4. Please add "use warning;" to your code and correct all warnings.
Regards,
Shlomi Fish
> # 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";
> }
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Why I Love Perl - http://shlom.in/joy-of-perl
Deletionists delete Wikipedia articles that they consider lame.
Chuck Norris deletes deletionists whom he considers lame.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/