I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2010-05-14 12:31:30.028264-07 by titang
Passing shared variables among subroutines for thread::shared variables

Please help. Here is my problem.

I wrote a program, uses threads::shared to share 2 variables ($x, %y). I access them in my subroutines called thread_xy. When I have the main program and the subroutine inside a single file, everything is Fine.

Now I put thread_xy into a Package called: myPackage.pm. It no longer work. I tried to declare the variable inside myPackage.pm, passing the variable within the thread_xy(...), and tried to use use "qw" etc. None worked: the shared variables I modified inside thread_xy(...) is not passed back to my main program.

How I can declare the shared variables correctly between the main program and a subroutine when I put the subroutine in a Package (separated from my main program)?

Direct Responses: 12705 | Write a response