Here's what I tried with XS:
my $a = [ 1 .. 10 ];
print "was: @$a\n";
Laff::dump_arrref($a);
in my XS:
void
dump_arrref(arrref)
SV* arrref
CODE:
{
int i,n,val;
AV* arr;
if (!SvROK(arrref))
croak("dump_arrref did not recieve a pointer");
arr = (AV*) SvRV(arrref);
if (!SvTYPE(arr))
croak("dump_arrref dif not recieve a pointer ot a list");
n = av_len(arr) + 1;
printf("is: ");
for (i = 0; i < n; i++)
printf(" %d",SvIV(*av_fetch(arr,i,0)));
printf("\n");
}
Here's the result:
dragon 10 % perl -Mblib x
Using /data/cdmg/dev/cdmg_toolbox/LaffPerl/../blib
was: 1 2 3 4 5 6 7 8 9 10
is: 1 2 3 4 5 6 7 8 9 10
I used the LaffPerl just because I already had it. Just stuck in the
dump_arrref
On Wed, 10 Jul 2002, Aaron J Mackey wrote:
>
> Check this out:
>
> #!/usr/bin/perl -w
> use strict;
> use Inline C => 'DATA';
>
> my $a = [ 1 .. 10 ];
> print "was: " . join(" ", @{$a}) . "\n";
> dump_arrref($a);
> __DATA__
> __C__
> void dump_arrref(SV* arrref) {
> int i, n, val;
> AV* arr = SvRV(arrref);
> n = av_len(arr) + 1;
> printf("is: ");
> for(i = 0 ; i < n ; i++) printf("%d ", SvIV(av_shift(arr)));
> printf("\n");
> }
>
>
> Yields:
>
> was: 1 2 3 4 5 6 7 8 9 10
> Use of uninitialized value in subroutine entry at test.pl line 9.
> Use of uninitialized value in subroutine entry at test.pl line 9.
> Use of uninitialized value in subroutine entry at test.pl line 9.
> Use of uninitialized value in subroutine entry at test.pl line 9.
> Use of uninitialized value in subroutine entry at test.pl line 9.
> is: 2 4 6 8 10 0 0 0 0 0
>
> This looks suspiciously like my array is being interpreted as a hash, or
> something. I don't get it. Help?!?
>
> -Aaron
>
> --
> Aaron J Mackey
> Pearson Laboratory
> University of Virginia
> (434) 924-2821
> [EMAIL PROTECTED]
>
>
>