in reply to Re^3: Can call array but not index of an array in subroutine?!
in thread Can call array but not index of an array in subroutine?!

Ok, I see you changed the lines inside the loop, to something that is definitely wrong as long as you don't change the rest. Please put it back as it were (i.e to @Axcord[$counter] =...). The code is not pretty, but it is not really wrong. Also add "\n" after your print statements so your debug output is not all on one line. You might also change one of the print lines this way to give more information:

print STDOUT "should print out \@Axcord array but does'nt?! |", join(' +|',@Axcord),"|",scalar(@Axcord),\n";

That will print '|' between anything that is in the array and also the size of the array. After that execute and tell us what gets printed and (if possible) what you would expect.

Also you might put similar print statements at the beginning of the subroutine to find out what input values the subroutine gets. Maybe the routine does everything right and it is the input that is wrong.

By the way, you forgot code tags around your data, this way it is unusable. But anyway it is a bit large, usually you should try to trim down the problem as much as you can, code as well as data.

Replies are listed 'Best First'.
Re^5: Can call array but not index of an array in subroutine?!
by fraizerangus (Sexton) on Apr 03, 2009 at 13:38 UTC
    Hi everyone! I've just found out the problem seems to be that some of the arrays I am creating are infact negative arrays?! does anyone know why this might be happening or what I can do to reverse it?! best wishes Dan

      What do you consider a "negative array"? Is it:

      1. A data structure where the index is arbitrary but the values are always the range 0 to (number of items-1)?
      2. A data structure where the values are arbitrary but the index is always in the range 0 down to -(number of items-1)?
      3. A normal array?

      If you're wondering, you can access Perl arrays with positive and negative values for the index, where positive values count from the front and negative values count from the end of the array.

        Sorry I did'nt really explain what I meant. The values are only acessible by using a negative index system, if I use the following loop, the array appears empty
        for ($i=0; $i >= 1000; $i++) { print STDOUT ("$Bxcoord[$i]"); }
        But if I use this loop I get the required values from the array.
        for ($i=0; $i >= -1000; $i--) { print STDOUT ("$Bxcoord[$i]"); }
        many thanks in advance! regards Dan