perllearner007 has asked for the wisdom of the Perl Monks concerning the following question:
#!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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why is there only one column in the output file?
by toolic (Bishop) on Apr 05, 2012 at 16:55 UTC | |
by perllearner007 (Acolyte) on Apr 05, 2012 at 20:52 UTC | |
|
Re: Why is there only one column in the output file?
by ryber (Acolyte) on Apr 05, 2012 at 17:01 UTC | |
by jwkrahn (Abbot) on Apr 05, 2012 at 21:46 UTC | |
by ryber (Acolyte) on Apr 06, 2012 at 14:13 UTC |