CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Sharing object in perl

 



samir.gambler
New User

Nov 23, 2011, 4:02 AM

Post #1 of 4 (2293 views)
Sharing object in perl Can't Post

I am creating an object like

Code
$ro_api  = Win32::OLE->new("xxx.xxx");


Now I want to share $ro_api with other thread.
If I am trying to do like scalar variable it is throwing error when i am using the $ro_api at later point.

Quote
PERL ERROR: Invalid value for shared scalar at...


Plzz help urgent...
Thanks


wickedxter
User

Nov 23, 2011, 5:31 PM

Post #2 of 4 (2272 views)
Re: [samir.gambler] Sharing object in perl [In reply to] Can't Post


Code
 
my $ro_api = Win32::OLE->new("xxx.xxx");

my $something = $ro_api->function;



samir.gambler
New User

Nov 24, 2011, 1:16 AM

Post #3 of 4 (2267 views)
Re: [wickedxter] Sharing object in perl [In reply to] Can't Post

Hello wickedxter,

What I am doing is something like this.

Code
use threads; 
use threads::shared;
use Win32::OLE;
my $ro_api:shared;

$ro_api = Win32::OLE->new("xxx.xxx");


As soon as controls comes to this line $ro_api = Win32::OLE->new("xxx.xxx");
It throws error PERL ERROR: Invalid value for shared scalar at...


budman
User

Feb 12, 2012, 11:57 AM

Post #4 of 4 (2041 views)
Re: [samir.gambler] Sharing object in perl [In reply to] Can't Post

Since a blessed object ref is returned, you need to use the shared_clone.
I don't have Windows to test, but did a sample below.

from docs: Shared variables can only store scalars, refs of shared variables, or refs of shared data.


$ro_api = Win32::OLE->new("xxx.xxx");


Code
package Test; 
use Moose;
has 'name' => ( is => 'rw', isa => 'Str');

package main;
use threads;
use threads::shared;

my $testobj = Test->new(name=>'test name');
my $var :shared = shared_clone($testobj);

print "Test: ",$testobj->name()."\n";
print "Var: ",$var->name(),"\n";


Test: test name
Var: test name

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives