(I originally asked this question on perlmonks, where it gathered lots of upvotes but zero answers.)
I want to write a C subroutine void alias(dest_package,dest_name,src_package,src_name) that implements something like *dest_package::dest_name = *src_package::src_name I'm having a lot of trouble with it. I think I have the right thing when *dest_package::dest_name already exists, but I don't know how to create it (with the proper refcounts) if it doesn't. Here's what I have now: static void alias(char* dest_package, char* dest_name, char* src_package, char* src_name) { HV* src_stash = gv_stashpv(src_package, 0); SV* src_glob = *hv_fetch(src_stash, src_name, strlen(src_name), 0); HV* dest_stash = gv_stashpv(dest_package, 0); SV** dest_globP = hv_fetch(dest_stash, dest_name, strlen(dest_name), 1); SV* dest_glob; if (dest_globP) { dest_glob = *dest_globP; } else { // WHAT GOES HERE? dest_glob = ...; } SvSetMagicSV(dest_glob, src_glob); } (hopefully I didn't mess that up when modifying it for posting.) I know I could do this by constructing the string "*dest_package::dest_name = *src_package::src_name" and passing it to eval_pv, and I may end up doing it that way, but for my own education if nothing else I'd love to know how to do this. Oh, and are my final arguments to hv_fetch correct? I'm not sure when you should set the lval attribute to true.