Hi, I have a tab delimited file where I want to split each column into array so that I can calculate the individual values of the column. I'm new to perl so I hope for some guidance.
In my text file : ID dataR1 dataR2 dataR3 ... 1 324 445 654 2 234 654 768.5 3 542.12 764 98.2 . . .
Right now, my code only can print out one value (dataR1) in OUT1. How do I actually put the whole values of dataR1 into the array to print out in OUT1? In addition, how do I use for loop to actually loop from dataR1 to dataR3 to put into different arrays instead of having to type out manually as different files has different number of dataRx.
for(my $i = 0; $i < $originalfilecount; $i++) { #read in the current file open CURINFILE, "<$files[$i]" or die "Error couldn't open file $fi +les[$i]\n"; print "$files[$i]\n"; while(<CURINFILE>) { chomp $_; my @columns = split('\t'); push(@ID, $columns[0]); push(@data1, $columns[1]); push(@data2, $columns[2]); push(@data3, $columns[3]); print "\nWriting output..."; mkdir "$pathname" or die "Error couldn't create new Directory"; open OUT1, ">$pathname/column.txt" or die "error couldn't open output +file"; print OUT1 "$data[1]" } close OUT1 }
Help appreciated :)

In reply to How to add column into array from delimited tab file by hellohello1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.