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


in reply to Re: average a column in tab-delimited file
in thread average a column in tab-delimited file

Yep,

you just can't start reading columns in a file. Cause there ain't any. There ain't no lines in a file actually either.

There is no spoooon.

Well that is - a text file in your computer should be just a big string of values. Those lines you see in your text editor are there only because once in a while in this big string there are line break characters, so your text editor can know when to make a break. No program can just bam go and start reading "columns" from this.

So you have to make those columns yourself. As fisher said - the basic algorithm is to take your file line by line, split those lines(by whatever separates your values(whitespace,comma or tab), then you take each fourth(counting from zero) element from those split lines(you were looking for an average of third column if i remember correctly. So if you append those fourth elements in an array, print out somewhere or whatnot, then you've got your third column.