liutingloveliu 2021-07-14 15:11 采纳率: 75%
浏览 104
已采纳

perl的for循环为什么只执行了一次

本意是想统计下表中第一列各个Scaffold的重复序列类型(即第4列)的情况
##FLIE3                                 
#Scaffold1        1       6567   LTR     LTR    
#Scaffold1        4236    20683  LTR     Gypsy  
#Scaffold2        18612   20763  LTR     Gypsy  
#Scaffold3        20764   25446  LTR     Gypsy  
#Scaffold1        25447   44695  LTR     LTR    
#Scaffold3        43913   59363  LTR     Gypsy  
#Scaffold5        44696   52695  LTR     Gypsy  
#Scaffold66        57364   89631  LTR     Gypsy  
#Scaffold96        78853   92154  LTR     Gypsy
#...

use strict;
open(FILE3,"/home/test/ltt/homework1/out3.gff");


for (my $i=1;$i<=96;$i++){
        my @line = ();
        my %has = ();
        foreach(<FILE3>){

                chomp;
                @line= split /\t/;
                if ($line[0] =~ /$i/){
                        $has{$line[3]}++;
                        $has{$line[3]}.="\n";
                        }
        }
        print "The situation of chromosome$i is:\n";
        print %has;
}

运行结果如下:
[test@login01 homework1]$ perl 7.sh
The situation of chromosome1 is:
 Unknown17445
 RC88
 Simple_repeat368
 DNA4947
 Satellite261
 LINE2156
 LTR77095
The situation of chromosome2 is:
The situation of chromosome3 is:
The situation of chromosome4 is:
The situation of chromosome5 is:
The situation of chromosome6 is:
The situation of chromosome7 is:
The situation of chromosome8 is:
The situation of chromosome9 is:
The situation of chromosome10 is:
The situation of chromosome11 is:
The situation of chromosome12 is:
The situation of chromosome13 is:
The situation of chromosome14 is:
The situation of chromosome15 is:
The situation of chromosome16 is:
The situation of chromosome17 is:
The situation of chromosome18 is:
The situation of chromosome19 is:
The situation of chromosome20 is:
The situation of chromosome21 is:
The situation of chromosome22 is:
The situation of chromosome23 is:
The situation of chromosome24 is:
The situation of chromosome25 is:
The situation of chromosome26 is:
The situation of chromosome27 is:
The situation of chromosome28 is:
The situation of chromosome29 is:
The situation of chromosome30 is:
The situation of chromosome31 is:
The situation of chromosome32 is:
The situation of chromosome33 is:
The situation of chromosome34 is:
The situation of chromosome35 is:
The situation of chromosome36 is:
The situation of chromosome37 is:
The situation of chromosome38 is:
The situation of chromosome39 is:
The situation of chromosome40 is:
The situation of chromosome41 is:
The situation of chromosome42 is:
The situation of chromosome43 is:
The situation of chromosome44 is:
The situation of chromosome45 is:
The situation of chromosome46 is:
The situation of chromosome47 is:
The situation of chromosome48 is:
The situation of chromosome49 is:
The situation of chromosome50 is:
The situation of chromosome51 is:
The situation of chromosome52 is:
The situation of chromosome53 is:
The situation of chromosome54 is:
The situation of chromosome55 is:
The situation of chromosome56 is:
The situation of chromosome57 is:
The situation of chromosome58 is:
The situation of chromosome59 is:
The situation of chromosome60 is:
The situation of chromosome61 is:
The situation of chromosome62 is:
The situation of chromosome63 is:
The situation of chromosome64 is:
The situation of chromosome65 is:
The situation of chromosome66 is:
The situation of chromosome67 is:
The situation of chromosome68 is:
The situation of chromosome69 is:
The situation of chromosome70 is:
The situation of chromosome71 is:
The situation of chromosome72 is:
The situation of chromosome73 is:
The situation of chromosome74 is:
The situation of chromosome75 is:
The situation of chromosome76 is:
The situation of chromosome77 is:
The situation of chromosome78 is:
The situation of chromosome79 is:
The situation of chromosome80 is:
The situation of chromosome81 is:
The situation of chromosome82 is:
The situation of chromosome83 is:
The situation of chromosome84 is:
The situation of chromosome85 is:
The situation of chromosome86 is:
The situation of chromosome87 is:
The situation of chromosome88 is:
The situation of chromosome89 is:
The situation of chromosome90 is:
The situation of chromosome91 is:
The situation of chromosome92 is:
The situation of chromosome93 is:
The situation of chromosome94 is:
The situation of chromosome95 is:
The situation of chromosome96 is:





![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/636156642626191.PNG)


img

  • 写回答

2条回答 默认 最新

  • ggeneral2 2021-07-15 19:45
    关注

    估计if ($line[0] =~ /$i/)这个条件只有第一次时候是满足的。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已采纳回答 7月18日
  • 创建了问题 7月14日

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来