Date sent: Tue, 30 Jul 2002 15:20:39 +0200
To: "Jenda Krynicky" <[EMAIL PROTECTED]>, perl5-
[EMAIL PROTECTED],
[EMAIL PROTECTED]
From: Elizabeth Mattijsen <[EMAIL PROTECTED]>
Subject: Re: Thread::Use - use a module inside a thread only
> At 02:54 PM 7/30/02 +0200, Jenda Krynicky wrote:
> >The problem with run-time "useit Foo" instead of compile-time "use
> >Foo" is that the symbols are not exported while compiling, prototypes
> >not "installed", constants not defined, etc. etc. etc.
>
> Well, I guess YMMV... prototypes aren't much use in an OO environment
> anyway, exports seems to work fine, judging from the testing that I
> did. Constants may be another problem, let me check up on that...
Even if there's no prototype defined for a function, the fact that
perl knows about it already IS important. Try to run this:
#perl
foo 1,2,3;
sub foo {print join(', ', @_), "\n"};
or this:
#perl
eval q{
sub foo {print join(', ', @_), "\n"};
};
foo 1,2,3;
I bet you'll see the same problems with "useit Module".
> >Would not it be simpler then to require() or do() the whole thread?
> > use threads;
> > $thread = threads->create(sub {do 'worker_thread.pl';}) ...
>
> Simpler by having to have a different file? That doesn't make it
> simpler for me... ;-)
Well, for the simple tests and benchmarks it seems to make things
more complex, but if you have anything longer than a few lines it is
better to separate it out into a different file anyway.
And if you do not like separating out into a file, you can use an
eval('...').
Anyway in almost all the threaded programs I ever made in Perl (Perl
5.6.1, Win32, fork(), no shared variables) I use do() and separate
files and it seems to work very well.
Jenda
P.S.: Since I need to be able to create .exe files out of the scripts
I'll stay on 5.6.1 until there's a version of ActiveState's PDK for
5.8. At least for production purposes.
=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
--- me