Hi Tassilo,

I've tried your first example and this doesn't seem to work

------------------
void
getprocs()
        PPCODE:
                HV *hv = newHV();

                hv_store(hv, "pi_pid", 6, newSViv(123456), 0);
                XPUSHs(sv_2mortal(newSVrv((SV*)hv)));
------------------

returned me: $VAR1 = undef;

would it be possible to send me a little working example?

thanx for your help


Yannick Bergeron




                                                                           
             Tassilo von                                                   
             Parseval                                                      
             <tassilo.von.pars                                          To 
             [EMAIL PROTECTED]         Yannick Y                           
             de>                       Bergeron/Bromont/[EMAIL PROTECTED]       
   
             Sent by: ethan                                             cc 
             <tassilo.von.pars         perl-xs@perl.org                    
             [EMAIL PROTECTED]                                     Subject 
             de>                       Re: XPUSHs a HV                     
                                                                           
                                                                           
             2005-02-21 05:55                                              
                                                                           
                                                                           
                                                                           




On Sun, Feb 20, 2005 at 04:36:52PM -0500 [EMAIL PROTECTED] wrote:
> I'm trying to push a HV on the stacks. I've tried with
> "XPUSHs(hv_scalar(hv));" but I get weird stuff when I print it with
> Data::Dumper ("$VAR1 = '1/8';")

'hv_scalar(hash)' is the XS equivalent to

    $scalar = %hash;

so that explains why you got '1/8' (meaning: one of eight buckets in the
hash are used; you can use this value to measure the amount of
collisions in case you're interested).

Returning a hash can happen in two ways. Either return a reference:

    XPUSHs(sv_2mortal(newSVrv((SV*)hv)));

or by returning the hash as a list, which is more cumbersome and slower:

    char *key;
    SV *val;
    I32 len;

    hv_iterinit(hv);
    while (val = hv_iternextsv(hv, &key, &len)) {
             XPUSHs(sv_2mortal(newSVpvn(key, len)));
             XPUSHs(val);
    }

The above might be a bit off as I've never used 'hv_iternextsv' before.

Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);



Reply via email to