开发者

Can one pass Perl hash references between processes?

I have an ActiveState PerlCtrl project. I'd like to know if it's possible to have a hash in the COM DLL, pass it's ref out to the calling process as a string (e.g. "HASH(0x2345)") and then pass that string back into the COM DLL and somehow bless it back into pointing to the relevant hash.

Getting the hashref seems easy enough, using return "" . \%Graph; and I have tried things like $Graph = shift; $Graph = bless {%$Graph}; but they don't seem to achieve what I'm after. The %Graph hash is at least global to the module.

The testing code (VBScript):

set o = CreateObject("Project.BOGLE.1")
x = o.new_gra开发者_运维百科ph()
wscript.echo x
x = o.add_vertex(x, "foo")


If these are different processes, you will need to either serialize the content of the hash or persistently store it in a disk file. To do the former, see Storable or Data::Dumper; for the latter, it depends whether it's a hash of simple scalars or something more complex.

If it is the same perl interpreter in the same process, you can keep some global variable like %main::hashes; set $main::hashes{\%Graph} = \%Graph before passing the stringified reference back to the calling process, then later use it to look up the actual hash reference.

Don't do this, though: http://perlmonks.org/?node_id=379395.


No, you can't reliably pass hash references between processes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜