免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2195 | 回复: 2
打印 上一主题 下一主题

数组splice的问题,请大家指点,不胜感谢!!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-10-25 21:18 |只看该作者 |倒序浏览
110.rar (154.28 KB, 下载次数: 45) 写了一段代码,希望将原始文件(见附件)的数据按照第二列进行合并,并把其作为一个hash元素记录在一个hash中。
但是运行是提示:splice () offset past end of array.(如图)。不知道这个指什么?还望大家指点,另外根据代码
输出的结果也不对, 不明白问题到底出在哪里?应该怎么修改下才能得到想要的结果,还请大家不吝赐教!!!谢谢!


代码如下:

#!/usr/bin/perl -w

print " Please enter the path of the mass_retention-time file:";
$MASS_RETENTION_TIME1=<STDIN>;
chomp $MASS_RETENTION_TIME1;
print " Please enter the path of the output file:";
$output=<STDIN>;
chomp $output;
open (RAWDATA, "$MASS_RETENTION_TIME1") ||die "Cannot open the file:"!";
open (OUTPUT, ">$output") ||die "Cannot open the file:"!";
@mass_retention_time=<RAWDATA>;


#Combination masses of the same retention time, formed the array: @mass_list.
#Generation the hash of retention time and mass list:%hash_RT_masslist.
for ($circle_time=1; @mass_retention_time > 0; $circle_time++)
{if ($mass_retention_time[0]=~/(\d+\.\d+)\s(\d+\.\d+)/)
        {$key=$2; $mass_list[0]=$1;}
if (@mass_retention_time>1)
  {$number=1;
   $list=0;
   for ($i=$#mass_retention_time; $i>=1; $i--)
     {$tmp_RT=0;
             if ($mass_retention_time[$i]=~/(\d+\.\d+)\s(\d+\.\d+)/)
             {$tmp_RT=$2; $tmp_mass=$1;}
      if ($tmp_RT eq $key)
       {$mass_list[$number]=$tmp_mass;
        $number++;
        $RT[$list]=$i;
        $list++;}
     }
  foreach $RT_list (@RT)
     {splice(@mass_retention_time, $RT_list, 1);}  

  }
$hash_RT_masslist{$key}=join(' ', @mass_list);
shift(@mass_retention_time);
}        
@RT_1=keys %hash_RT_masslist;
@RT_sorted=sort {$a<=>$b;} @RT_1;   


foreach $RT_sorted1 (@RT_sorted)
  {@RT_masslist=split(' ', $hash_RT_masslist{$RT_sorted1});
   print OUTPUT $RT_sorted1, "\n\n";
   foreach $RT_masslist1 (@RT_masslist)
     {print OUTPUT $RT_masslist1, "\n";}
   print OUTPUT "\n\n";
  }
  
close(RAWDATA);
close(OPUTPUT);

[ 本帖最后由 skybrain 于 2007-10-25 21:20 编辑 ]

RT_combine.rar

421 Bytes, 下载次数: 30

输入文件

Standard_Mixture.rar

347 Bytes, 下载次数: 34

输出文件

论坛徽章:
0
2 [报告]
发表于 2007-10-25 22:20 |只看该作者
#!/usr/bin/perl -w
use strict;
print " Please enter the path of the mass_retention-time file:";
my $MASS_RETENTION_TIME1=<STDIN>;
chomp $MASS_RETENTION_TIME1;
print " Please enter the path of the output file:";
my $output=<STDIN>;
chomp $output;
my %hash=();
open (RAWDATA, "$MASS_RETENTION_TIME1"  ) ||die "Cannot open the file: $!";
while(<RAWDATA> ){
    chomp;
    split /\s+/;
    push(@{$hash{$_[1]}},$_[0]);
}
close(RAWDATA);


open (OUT, ">$output") ||die "Cannot open the file: $!";
my $key=undef;
foreach $key(sort{$a<=>$b} keys %hash){
print OUT $key,"\t",join(' ',@{$hash{$key}}),"\n";
}


close(OUT);

[ 本帖最后由 smonkey0 于 2007-10-25 22:32 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2007-10-25 22:21 |只看该作者
显示那此讨厌的表情,真烦

[ 本帖最后由 smonkey0 于 2007-10-25 22:31 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP