in reply to Re^3: Error opening file handle within while loop
in thread Error opening file handle within while loop

$columns (or $columnsA, apologies this is just a discrepancy between versions of the script I'm testing) is filled as I expect if I print the array, however when I try to print a single column as a string it says it is uninitialized - I'm really not sure why this might be.
  • Comment on Re^4: Error opening file handle within while loop

Replies are listed 'Best First'.
Re^5: Error opening file handle within while loop (uninitialized value in array)
by hippo (Archbishop) on Feb 10, 2016 at 13:16 UTC

    Since you are new to coding my guess is because @columnsA (or whatever) has only 2 elements while your code thinks there are three. Arrays are indexed from zero upwards, not from one.

      This is a good suggestion, but there should be 7 elements in the array (or 0-6).

        What steps have you undertaken to ascertain your assumption?

        For example, the following prints the number of elements in the array @columns:

        print 0+@columns;

        And the following shows you the values of the elements:

        use Data::Dumper; print Dumper \@columns;

        Personally, I would always look at the line where @columns gets initialized, and also inspect the source data, by printing the line $line1.