Aaron J. Mackey <[EMAIL PROTECTED]> writes:
>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)));

SvIV is a macro that evaluates its argument more than once,
so you av_shift() more times than you think, and only printf some of them. 

Use a temporary:

  for(i = 0 ; i < n ; i++) {
     SV *sv = av_shift(arr);
     printf("%d ", SvIV(sv));
  }


>  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
-- 
Nick Ing-Simmons
http://www.ni-s.u-net.com/

Reply via email to