On Sat, Jul 21, 2007 at 01:16:16PM +0800, Justin Hammond wrote: <snip> > For FIRSTKEY and NEXTKEY, I'm a little confused what I should return > back. Do I return the actual HASH, or do I return the key name for > the value? > > Currently, I'm returning the HASH, and when doing the following code > in perl, I get the following output: > my $hostserv = new NeoStats::NV("HostServ"); > while ( my ($key, $value) = each(%$hostserv)) { > NeoStats::debug("Hostserv Key => $value"); > while ( my ($key1, $value1) = each(%$key)) { > NeoStats::debug("HS: $key: $key1 => $value1"); > } > } > > WARNING Test - Hostserv Key => HASH(0x1a702c0) > WARNING Test - HS: HASH(0x1a68f18): passwd => asasasd > <snip> > > As you can see, the "Key is actual a HASH". How do I get the actual > key used rather than this reference (note that FETCH works fine though)
In Perl you can never return an Array or Hash directly, only a reference to such (unless you get into list coercion, but that's clearly not what you want here). This goes for Perl or Perl XS. You can only return scalar values (strings, integers, references, etc) from routines. My XS is rusty, so I'll refrain from posting psuedo-code lest I confuse you. Hopefully you get the idea. I'm too tired/lazy to attempt a stab at your second question. Sorry ;)