in reply to Re^3: 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

Sorry..got really swamped at doing other things at work, plus, had several days of snow delays

It gives me "Thread X terminated abnormally: Invalid value for shared scalar at S:\Reports\NotWorking\Stats5c.pl line 594, <DATA> line 335"

<\p>

It's probably a warning -- in that it doesn't outrightly die on me.

Which of course means the hash population which this is supposed to be changing is unpopulated when it returns...

In my 'fiddling' with Threads::Shared, I wongled together a means of doing a single variable and field combo

E.G. $$dataref{$variable}{"FieldName"}++;

which seemed to work...

I may have to, while not ideal, split the %data hash into 2 or 3 hashes -- one part for the shared pieces (using a split-able string single level hash) and one for the unshared portions. And presumably use split to re-merge the shared portions back.

  • Comment on Re^4: Threads::Shared MultiLevel Hash and the Invalid value for Shared Scalar Error
  • Download Code

Replies are listed 'Best First'.
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

    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.