On Sun, 4 Feb 2001, Jack H. Stanley wrote:
> I applaud the latest release of Inline. I have integrated a complex API
> into Perl with ease. I would appreciate a reference to a method of
> returning an array of hashes.
>
Try this:
----8<----
use Inline 'C';
use Data::Dumper;
my @array = get_hashes();
print Dumper \@array;
__END__
__C__
void get_hashes() {
Inline_Stack_Vars;
HV *first_hash = newHV();
HV *second_hash = newHV();
U32 hash;
/* %first_hash = ( neilw => 'Neil Watkiss',
* jstanley => 'Jack H. Stanley',
* );
*/
PERL_HASH(hash, "neilw", 5);
hv_store(first_hash, "neilw", 5, newSVpv("Neil Watkiss", 0), hash);
PERL_HASH(hash, "jstanley", 8);
hv_store(first_hash, "jstanley", 8, newSVpv("Jack H. Stanley", 0),
hash);
/* %second_hash = ( 987654321 => "NEILW",
* 123456789 => "INGY",
* );
*/
PERL_HASH(hash, "987654321", 9);
hv_store(second_hash, "987654321", 9, newSVpv("NEILW", 0), hash);
PERL_HASH(hash, "123456789", 9);
hv_store(second_hash, "123456789", 9, newSVpv("INGY", 0), hash);
/* return (\%first_hash, \%second_hash); */
Inline_Stack_Reset;
XPUSHs(newRV_noinc(first_hash));
XPUSHs(newRV_noinc(second_hash));
Inline_Stack_Done;
}
----8<----
Good luck!
NeilW