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

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.

  • Comment on Re^6: Can call array but not index of an array in subroutine?!

Replies are listed 'Best First'.
Re^7: Can call array but not index of an array in subroutine?!
by fraizerangus (Sexton) on Apr 03, 2009 at 14:02 UTC
    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

      Why are you sure that your loop is ever even entered? You got a condition that is wrong at the start of the loop:

      for ($i=0; $i >= 1000; $i++) {

      This is why it is much much better to use foreach to loop over arrays instead of using the C-style loop. Or, if you want to just look at an array, use Data::Dumper or a simple print statement:

      print "@Bxcoord";