Thanks to all. Some hard meditation and I've gotten to a simplified skeleton that I think solves everything. If you see anything worth warning me about, I would love to hear it.
I'm putting the proof of concept code in <readmore> tags. The work file was called "sharedanonymoushashrefs.pl", so that explains some of the naming conventions (sahr_).
#!/usr/bin/perl -w use strict; use threads; use threads::shared; use Thread::Queue; my $qQueue0 = Thread::Queue->new; my $qQueue1 = Thread::Queue->new; my $href; $href = &share({}); $href->{'a'}=1; $href->{'b'}=2; $href->{'c'}=3; $href->{'d'}=4; print "before enqueue\n"; printKeys($href); print "\n"; $qQueue0->enqueue($href); $href = &share({}); $href->{'e'}=5; $href->{'f'}=6; $href->{'g'}=7; $href->{'h'}=8; print "before enqueue\n"; printKeys($href); print "\n"; $qQueue0->enqueue($href); $qQueue0->enqueue(undef); my $sahr_thread = threads->new(\&sahr_thread, $qQueue0, $qQueue1); $sahr_thread->join; while ($href = $qQueue1->dequeue) { print "Results\n"; printKeys($href); print "\n"; } sub printKeys { my $loc_href = shift; print "KEYS : "; print(($_).' ') foreach (sort keys %{$loc_href}); print "\nvalues: "; print(($$loc_href{$_}).' ') foreach (sort keys %{$loc_href}); print "\n"; } sub sahr_thread { my ($inqueue, $outqueue) = @_; my %inhash; my $inhashref; my $outhashref; while ($inhashref = $inqueue->dequeue) { %inhash = %{$inhashref}; print "within thread - inhash\n"; printKeys (\%inhash); print "\n"; $outhashref = &share({}); %$outhashref = (%inhash); $outhashref->{z} = 9; $outhashref->{y} = 8; print "within thread - outhash\n"; printKeys ($outhashref); print "\n"; $outqueue->enqueue($outhashref); } }
In reply to Re^2: scalars, references and queues
by Anonymous Monk
in thread scalars, references and queues
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |