> Did you see the message I sent to the list this morning on creating
> hashes? Here it is again:
Of course, you don't have to return a reference... you could return a
flattened hash:
----------8<--------------
use Inline C => 'DATA';
my %people = get_people();
for (sort keys %people) {
print "$_ is $people{$_}\n";
}
__END__
__C__
typedef struct conv {
char *person;
char *attribute;
} conv;
/* One interpretation of a hash in C */
static conv people[] = {
{"Neil", "cool"},
{"Ingy", "alright"},
{"Jan", "solemn"},
{0, 0} /* end flag */
};
/* returns a flattened hash */
void get_people() {
int i;
Inline_Stack_Vars;
Inline_Stack_Reset;
for (i=0; people[i].person != 0; i++) {
Inline_Stack_Push(newSVpv(people[i].person,0));
Inline_Stack_Push(newSVpv(people[i].attribute,0));
}
Inline_Stack_Done;
}
----------8<--------------
Apart from making the C much simpler, this approach has the advantage of
making your Perl code clearer. Someone reading your code can tell there's
a hash being assigned.
TMTOWTDI!
Neil