开发者

How to get user input for the column label probeid in this program

My data has 170 rows (exp.values) and 18,000 columns (Probeid's). If i enter a specific probeId, I need the particular column to be开发者_JS百科 retrieved. And that probeid will be entered during run time. Does anyone have an idea? I have no problem with the output for this program. This program does the task for the id P_170221 that is entered while coding.When I tried entering variable $probeid (which is got by STDIN) in place of P_170221, I got error like:

Use of uninitialized value in concatenation (.) or string at C:/Users/xxx/perl_workspace/perl_proj_one/GIS/just.pl line 16, <> line 1.

#!/usr/bin/perl
use strict;
use warnings;
use Tie::Handle::CSV;
open(OUT,">C:\\Users\\xxx\\Desktop\\Output.txt")||die $!;
my $fh = Tie::Handle::CSV->new("C:\\Users\\xxx\\Desktop\\GE_Acc.csv", header => 1);

while (my $csv_line = <$fh>) {
   print OUT $csv_line->{'FID'} . ", " . $csv_line->{'IID'} .",".$csv_line->{'P_1710221'}."\n";
    my $i++;
}

close $fh;


You get a normal hash reference for each line, iterate over its keys. Here I sort the keys because you probably don't want to go through them in random order:

while (my $csv_line = <$fh>) {
    print OUT $csv_line->{'FID'} . ", " . $csv_line->{'IID'};
    foreach my $key (sort keys %$csv_line) {
        # Ignore columns that aren't probeids
        next if $key eq 'FID' or $key eq 'IID';  

        print ", " . $csv_line->{$key};
    }
    print "\n";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜