in reply to Shared Hash-of-Arrays between threads?
Do you mean something like this? ...
sub createContract { + $key = "123456789"; + # If you want to share a newly created reference unfortunately # you need to use "&share([])" and "&share({})" syntax due to # problems with Perl's prototyping. # man page + + $Contracts{$key} = &share([]); $Contracts{$key}[0] = 100; $Contracts{$key}[1] = 200; $Contracts{$key}[2] = 300; $Contracts{$key}[3] = 400; + printf " %s %u^%u^%u^%u^\n", $key, $Contracts{$key}->[0], $Contracts{$key}->[1], $Contracts{$key}->[2], $Contracts{$key}->[3], ; } # Generates ... 123456789 100^200^300^400^ 123456789 100^200^300^400^
I haven't done a LOT with shared data in Perl (okay, to be honest just 1 program, where I used only shared scalars, or Thread::Queue for anything more complex), but it seems to work when you define the thing being shared first, and *then* assign to it.
|
|---|