Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^5: Threads::Shared MultiLevel Hash and the Invalid value for Shared Scalar Error

by BrowserUk (Patriarch)
on Feb 13, 2014 at 08:18 UTC ( [id://1074764]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Threads::Shared MultiLevel Hash and the Invalid value for Shared Scalar Error
in thread Threads::Shared MultiLevel Hash and the Invalid value for Shared Scalar Error

There are many anomalies in your OP code.

For example, you have many blocks of code like this:

unless (exists $$dataref{$eid}{"ALL"}{"MatchesPeopleEn +ded"}){ my %a :shared; $$dataref{$sid}{"ALL"}{"MatchesEnded"}=\%a; }

Note that you are testing exists $$dataref{$eid}{"ALL"}{"MatchesPeopleEnded"})

But are assigning to $$dataref{$sid}{"ALL"}{"MatchesEnded"}=\%a;

That probably explains your immediate problem. However, there are further anomalies.

For example, why are you assigning references to shared hashes to a bunch of variables that you subsequently are using as integers:

$$dataref{$sid}{"ALL"}{"MatchesStarted"}++; $$dataref{$sid}{"ALL"}{"MatchesPeopleStarted"} += $tn; $$dataref{$sid}{$whichco}{"MatchesPeopleStarted"} += $tn; $$dataref{$sid}{$whichco}{"MatchesStarted"}++; $$dataref{$eid}{"ALL"}{"MatchesEnded"}++; $$dataref{$eid}{"ALL"}{"MatchesPeopleEnded"} += $tn; $$dataref{$eid}{$whichco}{"MatchesPeopleEnded"} += $tn; $$dataref{$eid}{$whichco}{"MatchesEnded"}++;

Part of your problem is that you spread your code around all over the place which means that you need to scroll up down many pages to see where a variable is declared, initialised and then used.

There is a huge chunk of code in the middle of your program that I suspect could be replace by this:

$$dataref{$sid} //= &shared({}); $$dataref{$sid}{"ALL"} //= &shared({}); $$dataref{$sid}{"ALL"}{"MatchesStarted"}++; $$dataref{$sid}{"ALL"}{"MatchesPeopleStarted"} += +$tn; $$dataref{$sid}{$whichco} //= &shared({}); $$dataref{$sid}{$whichco}{"MatchesPeopleStarted"} ++= $tn; $$dataref{$sid}{$whichco}{"MatchesStarted"}++; $$dataref{$eid} //= &shared({}); $$dataref{$eid}{"ALL"} //= &shared({}); $$dataref{$eid}{"ALL"}{"MatchesEnded"}++; $$dataref{$eid}{"ALL"}{"MatchesPeopleEnded"} += $t +n; $$dataref{$eid}{$whichco} //= &shared({}); $$dataref{$eid}{$whichco}{"MatchesPeopleEnded"} += + $tn; $$dataref{$eid}{$whichco}{"MatchesEnded"}++;

Which might improve things a little, but I have no way to test that.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1074764]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-19 15:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found