我正在尝试从 C 库中创建 Perl 哈希。这是我到目前为止所得到的:
static void add_string_to_perl_hash ( HV *hv, char * key, char *value ) {
SV *obj = sv_2mortal(newSVpv(value, 0));
hv_store(hv, (const char *)key, strlen (key), obj, 0);
SvREFCNT_inc(obj);
}
SV * do_get_test_hash () {
static char *foo ="foo";
static char *bar ="bar";
HV *hv;
hv = newHV();
add_string_to_perl_hash ( hv, "foo", foo);
add_string_to_perl_hash ( hv, "bar", bar);
return sv_2mortal(newRV_noinc((SV*)hv));
}
尝试一下:我没有得到任何对我有意义的东西:
use testlib;
use Data::Dumper;
print Dumper (testlib::do_get_test_hash());
$VAR1 = bless( do{\(my $o = 5359872)}, '_p_SV' );
想法?