On 21 Jul 2007, at 1:54 PM, William Ahern wrote:
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 ;)
Hi,
I figured out the FIRSTKEY, NEXTKEY issue and got that working
correctly now, but still got a problem with the STORE function.
I'm wondering if I have to use magic on all levels in a nested hash?
If I use DUMP on the different levels of the HASH, I see magic
applied to all variables upto the last one. eg:
Dump($hostserv) <- got magic
Dump($hostserv->{0}) <- got magic
Dump($hostserv->{0}->{nick}) <- No magic
In my XS code, I'm only applying magic to the $hostserv variable, and
not the nested hashs, but from reading other code, it seemed to be
"inherited". Any ideas?
Thanks