in reply to Re: share array of hashes between main program and thread
in thread share array of hashes between main program and thread

Thank, that solved the problem. now i would like ask in addition, how could i add an additional single hash to a line i ($i) of my array of hashes after the line:
push( @{$Array_ref} , \%hash );
for example, i create my array of hashes (in a thread) and then send the array of hashes reference to an additional function. Then i tried (in the new function)
@Array = @$Array_ref; $Array[$i]{'foo'}->$boo
once i tired to call the new hash (in line i)  $Array[$i]{'foo'} i got an error massage of uninitialized value. I can think of the reason why it is like that and that is since my new hash i am trying to add is not "shared"... but i dont know how to add a single shared hash to $Array$i. thanks

Replies are listed 'Best First'.
Re^3: share array of hashes between main program and thread
by BrowserUk (Patriarch) on Nov 11, 2009 at 07:51 UTC
    how could i add an additional single hash to a line i ($i) of my array of hashes

    Do you mean: how can I add an extra key-value pair to one of the hashes in my AoH?

    Assuming you do, like this:

    $Array[ $i ]{ newKey } = 'newValue'.

    Once the reference is shared (or is a reference to a shared hash--same thing), adding pairs is just the same as normal. Because scalars, (keys and values) are shared by value. Only references are shared by reference.


    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.
      are the two command equivalent?
      $Array[ $i ]{ newKey } = 'newValue' $Array[ $i ]{ newKey }->'newValue'
      thanks
        are the two command equivalent?

        Not even slightly, as the latter is illegal syntax:

        perl -mstrict -cwle"$Array[ $i ]{ newKey }->'newValue'" String found where operator expected at -e line 1, near "->'newValue'" (Missing operator before 'newValue'?) syntax error at -e line 1, near "->'newValue'" -e had compilation errors.

        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.