How can I use Perl extract a particular column from a tab-separated file?

前端 未结 4 1069
灰色年华
灰色年华 2020-12-12 05:57

I am really new at Perl and have been trying to piece together a solution for this. When I run this program I don\'t get any errors and it doesn\'t display anything.

4条回答
  •  感动是毒
    2020-12-12 06:26

    Try this instead:

    #!/usr/bin/perl
    use strict;
    use warnings;
    
    open (DATA, ";
    my @header_titles = split /\t/, $header;
    my $extract_col = 0;
    
    for my $header_line (@header_titles) {
      last if $header_line =~ m/$search_string/;
      $extract_col++;
    }
    
    print "Extracting column $extract_col\n";
    
    while ( my $row =  ) {
      last unless $row =~ /\S/;
      chomp $row;
      my @cells = split /\t/, $row;
      print "$cells[$extract_col] ";
    }
    

提交回复
热议问题