in reply to Re^4: handling tab delimited files
in thread handling tab delimited files

how should i put it back together?

You could write

foreach my $val (@values){ $val *= $df * 50 ; } print join("\t", @values), "\n";

This would modify the values in-place in the array (because $val is an alias for the respective elements in the array), so you can simply join them with a tab after the for loop.

Or shorter, with map:

print join("\t", map { $_ * $df * 50 } @values), "\n";

or maybe even

... while (<FILE>){ print join("\t", map { $_ * $df * 50 } split /\t/), "\n"; }

Replies are listed 'Best First'.
Re^6: handling tab delimited files
by shaludr (Initiate) on May 05, 2010 at 20:41 UTC
    Hey thanks a lot. This is working. I want to insert a header to the output file ? do you know how i can do that? I want the results to be printed in a new file. it has to be 7 X 10. how should i set values to 7 columns X 10 rows ?
      I want to insert a header to the output file

      Just print it :)  — before printing the rows with the numbers:

      print "my header ...\n"; while (<FILE>){ ...
      I want the results to be printed in a new file.

      Either redirect the program's output (stdout) to a file using the shell, or explicitly open another file for output, and then print to that file handle:

      ... open OUTFILE, ">", "outfile.txt" or die $!; print OUTFILE "my header ...\n"; while (<FILE>){ print OUTFILE join("\t", map { $_ * $df * 50 } split /\t/), "\n"; }
      it has to be 7 X 10. how should i set values to 7 columns X 10 rows ?

      There isn't really anything to "set".  If you print 10 lines (rows) with each containing 7 tab separated values, you're done, essentially... i.e. the file will have 7 columns X 10 rows.  This would happen without further ado (with the code we have so far), provided the input file also has the same dimensions (which is seems to have (at least the columns), judging by your sample data).

        I was able to get the output in a new file... but header and the 7 X 10 does not work. no luck!!!