Re: XS hoh
[email protected] (Dominique Dumont)
| Newsgroups | perl.xs |
|---|---|
| Message-ID | <[email protected]> |
On Thursday 01 April 2010 21:24:56 Patrick Dupre wrote:
> I am trying similar as in perl:
> $HOH {A}{X}=a;
> $HOH {B}{Y}=b;
>
> but by using:
>
Let's translate your XS in Perl
> h_AB = newHV () ;
my %h_AB ;
> hoh = newHV () ;
my %hoh;
> hv_store (h_AB, "X", 1, newSVnv (a), 0) ;
$h_AB{X}='a';
> hv_store (hoh, "A", 1, newRV_inc ((SV*) h_AB), 0) ;
$hoh{A}=\%h_AB ;
> hv_store (h_AB, "Y", 1, newSVnv (b), 0) ;
$h_AB{Y}='b';
> hv_store (hoh, "B", 1, newRV_inc ((SV*) h_AB), 0) ;
$hoh{B}=\%h_AB ; # uh oh
> I get:
> 4 entries:
> A, X
> A, Y
> B, X
> B, Y
Which is expected because $hoh{A} and $hoh{B} refer to the same hash.
> How can I avoid such a behavior ?
By creating a *3rd* hash.
HTH
Dominique
--
http://config-model.wiki.sourceforge.net/ -o- http://search.cpan.org/~ddumont/
http://www.ohloh.net/accounts/ddumont