http://www.perlmonks.org?node_id=479471


in reply to Yet another array problem

From the line immediately following your commented line "#this works", you attempt to overwrite your array @line1 by splitting the numbers out of @line1, except you've forgotten to specify that you want it to operate on @line1, so instead it's operating on $_.

So, not only is it operating on the wrong variable, it also destroys the array that had the correct information. Overwriting variables like this is not generally a good idea.

If you don't need the intermediate result learn how to chain the operations together, or how to dereference things correctly. I'd suggest placing the data read from the file into a two dimensional array as you're reading it in, rather than keeping the lines as they were read, and then later attempting to split everything out.

-Scott