删除某些字段之间的空格,但不删除其他字段

时间:2014-04-11 08:13:02

标签: perl

我对此感到非常沮丧,如果有人能提供帮助,我将非常感激。我想改变它,以便最后3个字段一起打印而不是用空格分隔,但保留第一个字段后面的空格。提前谢谢!

#!/usr/bin/perl

my %throne = ('Ala' => 'A',
              'Cys' => 'C',
              'Asp' => 'D',
          'Pro' => 'P',
          'Val' => 'V',
          'Leu' => 'L',
          'Ile' => 'I',
          'Met' => 'M',
          'Phe' => 'F',
          'Tyr' => 'Y',
          'Trp' => 'W',
          'His' => 'H',
          'Lys' => 'K',
          'Arg' => 'R',
          'Gln' => 'Q',
          'Asn' => 'N',
          'Glu' => 'E',
          'Ser' => 'S',
          'Thr' => 'T',
          'Gly' => 'G');


while(<>)
{
    chomp;
    my @fields = split;
    print $fields[0] . " " . $throne{$fields[1]} . " " . $fields[2] . " " . $throne{$fields[3]} . "\n";
}

1 个答案:

答案 0 :(得分:0)

这就是你想要的吗?

print $fields[0] . " " . $throne{$fields[1]} . $fields[2] . $throne{$fields[3]} . "\n";