Mike,

Mike Pomraning schreef:

>>> It would be very helpful if you would post a "complete" example that
>>> shows the problem you're having.
>> OK. In short a small test-program: (I left out the standard "REAPER"-code).

> (``$SIG{CHLD} = \&REAPER'' is an interprocess construct put forth in
> perlipc, not an interthread construct.  Not sure what effect you intend it
> to have.)

I usually add this to take into account the situation where a thread
dies without a proper "return". It's not necessairy here.


>> Now, what I do is change the code so that the main program is in one
>> file "thr1.pl" and the thread-code is in a second file "thr1_sub.pm".
>> This file is "included" into the main program using a "require" line.

> This is a scoping issue, not a threads issue.  Code executed via 'do-FILE',
> 'require' or 'use' cannot see the lexicals in the enclosing scope of the
> doer, the requirer or the user. ...

Well, I did guess it was a scope-problem but it's one that props up due
to the use of treads (actually, due to the use of shared variabels for
threads).








>> So, in fact, it's exactly the same program, but split up in two files.
>> (if you have a lot of threads, this is a lot easier to manage then to
>> have everything in one file).
> ...
>> So, the variable "a" is not shared anymore!

> Your $a (well, my $a) in main is not the same as the $a in the .pm file.

Agreed, but that's exactly my problem.


But, yesterday-evening I did find a solution myself. In the manpage
"perlfunc" there is a line which says this. (it is about "do"):

do EXPR
Uses the value of EXPR as a filename and executes the contents of the
file as a Perl script.
        do 'stat.pl';
is just like
        eval `cat stat.pl`;


So I tried it; replace the 'require "./thr1_sub.pm"' with "eval `cat
thr1_sub.pm`;"

And .. hup hup ... barbatruk ... it works!

:-)




> Regards,
> Mike
Cheerio! Kr. Bonne.

Reply via email to