[Bioperl-l] weird behavior of arrary reference arguments for a subroutine

Guojun Yang gyang at plantbio.uga.edu
Thu May 19 11:27:11 EDT 2005


Dear All,
I have a subroutine that uses several array references as arguments (the arrays are produced earlier by another subroutine, and the array contents are correct when I print them out). But when I use the references as arguments for subroutine, it seems they are in wrong order. See sub below:

@A=(1, 3, 5, 7);
@B=(2, 4, 6, 8);
@C=(11,13, 15, 17);
@D=(12, 14, 16, 18);

sub test {
# example use: test(\@A, \@B, \@C, \@D)

      my $X=1;
      while (${$_[0]}[$X]) {
   print "A:${$_[0]}[$X] B:${$_[1]}[$X]\n";

        my $Y=1;
        while (${$_[2]}[$Y]) {
           .....
        $Y+=1;
        }
      $X+=1;
      }

I expect the result would print:
A:1 B:2
A:3 B:4
A:5 B:6
A:7 B:8

But the real print out is something like:
...(these may be correct ones).
A:1 B:14
A:1 B:16
A:1 B:18
...
A:15 B:6
A:15 B:8
...

Does anybody have a clue on the weird thing?
Thank you!
Guojun

Department of Plant Biology
University of Georgia




More information about the Bioperl-l mailing list