#!usr/bin/perl -w use strict; # open the file that has to be read my $input = "Users/Dektop/file123.txt"; die "Cannot open $input\n" unless (open(IN, $input)); #open a new file which has to be made open (my $out, ">outfile123.txt"); #In the while loop, put the columns that have to be printed in the new + file. while(<IN>){ my @fields = split /\t/,$_; my $ID = $fields[0]; my $WEIGHTED_SUM = $fields[9]; #print the columns { print $out "$ID\ $WEIGHTED_SUM \n"; } } #close the filehandles close($input); close($out);
The output file is extracting the ID column but for the WEIGHTED_SUM , I get the following error, Use of uninitialized value $WEIGHTED_SUM in concatenation (.) or string at sample1.pl line 20, <IN> line 2148788.
Can some tell me what is going on and why I am not able to extract both the columns? Is there a way to fix it?
In reply to Why is there only one column in the output file? by perllearner007
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |