[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Unexpected Splice behavior?



The following code produces the unexpected results. When it is run as
written, it prints 2 3 4 as opposed to the expected 3 4. When the < sign in
the if line is changed to >, it prints 1 2 3 as expected. How come? A
possible bug in Perl or MacPerl?

I'm using the most recent version of MacPerl on LC III.

Xiao-Jun Ma


@a = (1,2,3);
append(*a);

sub append {
   local(*ary) = @_;
   push (@ary, 4);
   for ($i = 0; $i < @ary; $i++) {
      if ($ary[$i] < 3) {
         splice(@ary, $i, 1);
       }
   }
}

print "@a\n";