#include #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "get-hash-value.h" void get_hash_value (HV * hash) { const char * key = "test-key"; SV * key_sv; key_sv = newSVpv (key, strlen (key)); if (hv_exists_ent (hash, key_sv, 0)) { HE * he; SV * val; char * val_pv; int val_length; int val_iv; printf ("The key for '%s' seems to exist.\n", key); he = hv_fetch_ent (hash, key_sv, 0, 0); val = HeVAL (he); val_pv = SvPV (val, val_length); printf ("As a string, its value is '%s' (length %d).\n", val_pv, val_length); if (SvIOK (val)) { val_iv = SvIV (val); printf ("As a number, its value is '%d'.\n", val_iv); } else { printf ("Perl doesn't think it's a number.\n"); } } else { printf ("The key for '%s' doesn't seem to exist.\n", key); } }