Roman Porizka <[EMAIL PROTECTED]> writes:
>Hello,
>I'm trying to exchange values in two hashes. These values are lists of
>hashes. I tryied to use combination of hv_fetch and hv_store, but it didn't
>work:
>
>SV ** temp_loop1;
>SV ** temp_loop2;
>
>
>temp_loop1 = hv_fetch(temp_include,"some_key",strlen("some_key"),0);
>temp_loop2 = hv_fetch(param_map[0],"some_key",strlen("some_key"),0);
>
>hv_store(param_map[0],"some_key",strlen("some_key"),*(temp_loop1),0);
>
>After this, there are the same values in temp_loop1 and temp_loop2.

You only show 1 store - did you really mean exchange?

As you might guess from the return type of SV ** fetch returns a pointer
to location where SV * is stored. So if you change the value in hash 
you fetched from the SV ** stays the same (for a particular key, and 
assuming there is no "tie" or magic involved) but the SV * stored there 
changes. So you need to save the SV * :

temp_loop1 = hv_fetch(temp_include,"some_key",strlen("some_key"),0);
temp_loop2 = hv_fetch(param_map[0],"some_key",strlen("some_key"),0);
SV *temp_val = *temp_loop1;
SV *param_val = *temp_loop2;

hv_store(param_map[0],"some_key",strlen("some_key"),temp_val,0);
hv_store(temp_include[0],"some_key",strlen("some_key"),param_val,0);

If there _is_ "tie" or magic involved then you are probably better 
off making copies:

SV *temp_val = newSVsv(*temp_loop1);
hv_store(param_map[0],"some_key",strlen("some_key"),temp_val,0);


>
>
>                                       Thanks for any informations
>
>                                                       Roman Porizka
-- 
Nick Ing-Simmons
http://www.ni-s.u-net.com/

Reply via email to