Greetings, Veltro,

I came back to revisit this and did a test. There is a bug in MCE::Shared. The shared hash via the TIE interface and specifying the module option, set to 'MCE::Shared::Hash', should deeply-share automatically when passing key-value pairs during construction.

Thank you, for posting. I will make a new release v1.837 with the fix.

Test Script

use strict ; use warnings ; use feature 'say' ; use Clone 'clone' ; use MCE::Hobo ; use MCE::Shared ; use Data::Dumper ; my $data = { key => 1, nested => { key => 1 } } ; tie my %hash_a, 'MCE::Shared', { module => 'MCE::Shared::Hash' }, %{ c +lone($data) } ; tie my %hash_b, 'MCE::Shared', { module => 'MCE::Shared::Hash' } ; tie my %hash_c, 'MCE::Shared', %{ clone($data) } ; # defaults to MCE: +:Shared::Hash tie my %hash_d, 'MCE::Shared' ; %hash_b = %{ clone($data) } ; %hash_d = %{ clone($data) } ; mce_async { $hash_a{key}++ ; $hash_a{nested}{key}++ ; $hash_b{key}++ ; $hash_b{nested}{key}++ ; $hash_c{key}++ ; $hash_c{nested}{key}++ ; $hash_d{key}++ ; $hash_d{nested}{key}++ ; my $_a = $hash_a{nested} ; $_a->{key}++ ; my $_b = $hash_b{nested} ; $_b->{key}++ ; my $_c = $hash_c{nested} ; $_c->{key}++ ; my $_d = $hash_d{nested} ; $_d->{key}++ ; say "ref nested_a: ", ref($_a) ; say "ref nested_b: ", ref($_b) ; say "ref nested_c: ", ref($_c) ; say "ref nested_d: ", ref($_d) ; say "" ; } ; MCE::Hobo->waitall ; say "a: ", Dumper( tied(%hash_a)->export ) ; # not deeply shared say "b: ", Dumper( tied(%hash_b)->export ) ; # ok say "c: ", Dumper( tied(%hash_c)->export ) ; # ok say "d: ", Dumper( tied(%hash_d)->export ) ; # ok

Output

ref nested_a: HASH ref nested_b: MCE::Shared::Object ref nested_c: MCE::Shared::Object ref nested_d: MCE::Shared::Object a: $VAR1 = bless( { 'key' => 2, 'nested' => { 'key' => 1 } }, 'MCE::Shared::Hash' ); b: $VAR1 = bless( { 'key' => 2, 'nested' => bless( { 'key' => 3 }, 'MCE::Shared::Hash' ) }, 'MCE::Shared::Hash' ); c: $VAR1 = bless( { 'key' => 2, 'nested' => bless( { 'key' => 3 }, 'MCE::Shared::Hash' ) }, 'MCE::Shared::Hash' ); d: $VAR1 = bless( { 'key' => 2, 'nested' => bless( { 'key' => 3 }, 'MCE::Shared::Hash' ) }, 'MCE::Shared::Hash' );

Changes

In the meantime, here are the changes needed in your script to run properly (3 places). The ref is a 'MCE::Shared::Object'.

47,48c47,48 < tie %{$test}, 'MCE::Shared', { module => 'MCE::Shared::Hash' }, %{$_ +test} ; < print Dumper( $test ) ; --- > tie %{$test}, 'MCE::Shared', %{$_test} ; > print Dumper( tied(%{$test})->export ) ; 54c54 < if ( ref $in->{ $_ } eq 'HASH' ) { --- > if ( ref $in->{ $_ } ) { 79c79 < print Dumper( $test ) ; --- > print Dumper( tied(%{$test})->export ) ;

Regards, Mario


In reply to Re: Hobo with a bit of recursion by marioroy
in thread Hobo with a bit of recursion by Veltro

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.