Ah, indeed that does do what I want (interesting technique!).  But I looked
at that and realized what my problem was in the original perl script.  I
didn't do $hash->{$thing}.  I used $hash{$thing}, which was wrong.  Talk
about getting bogged down in details.  Sorry for the basic perl error. (it
didn't even appear in the email, typical).

My second question is still out there, however, about perl "running-away" at
the end of the script.

Thanks.

-- 
Jeff Walker                   MatchLogic, Inc.
[EMAIL PROTECTED]        7233 Church Ranch Blvd.
Voice 1 (303) 222-2105        Westminster, CO  80021
Fax   1 (303) 222-2001        www.matchlogic.com


> -----Original Message-----
> From: Brian Ingerson [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 03, 2001 9:28 AM
> To: Jeff Walker
> Cc: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
> Subject: Re: make a hash from .xs file
> 
> 
> Jeff Walker wrote:
> > 
> > I am trying to build a hash from an .xs file, then return a 
> ref to that hash
> > to the perl code.  I figured out how pass the hash back 
> using a reference,
> > but when I get the hash back, all the keys exist, but all 
> the values are
> > undefined.  Here is some stripped down code that illustrates this:
> > 
> > SV *
> > Blah()
> >         PREINIT:
> 
> 8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<
> 
> > 
> > The perl program (which of course uses the module) get the 
> ref returned by
> > Blah.  I then print the keys of this hash and everything is 
> okay.  Then I
> > try to see the values (foreach $thing ( keys( %$hash ) ) ) 
> but they are all
> > not defined (via ! defined($hash{$thing} ))
> 
> Jeff,
> Here is script using Inline.pm that does what you want. 
> 
> --------------------------8<----------------------------
> use Inline C => DATA;
> 
> $hash_ref = my_new_hash(100);
> foreach $key (keys %$hash_ref) {
>     print "$key => $hash_ref->{$key}\n";
> }
> 
> __END__
> 
> __C__
> 
> SV* my_new_hash(int size) {
>     int i;
>     HV* hash = newHV();
>     for (i = 0; i < size; i++) {
>         hv_store_ent(hash, newSVpvf("string #%d", i), 
>                      newSViv(i), 0);
>     }
>     return newRV_noinc((SV*) hash);
> }
> --------------------------8<----------------------------
> 
> You'll need Inline.pm version 0.30. Just run the script. No compiling
> needed.
> 
> If you have any Inline related questions/problems, please post them to
> [EMAIL PROTECTED]
> 
> Brian
> 
> -- 
> perl -le 'use Inline C=>q{SV*JAxH(char*x){return newSVpvf
> ("Just Another %s Hacker",x);}};print JAxH+Perl'
> 

Reply via email to