数组splice的问题,请大家指点,不胜感谢!!!
数组splice的问题,请大家指点,不胜感谢!!!
作者提供的相关的附件(大小:1 K)
作者提供的相关的附件(大小:1 K)
作者提供的相关的附件(大小:154 K)
写了一段代码,希望将原始文件(见附件)的数据按照第二列进行合并,并把其作为一个hash元素记录在一个hash中。
但是运行是提示:splice () offset past end of array.(如图)。不知道这个指什么?还望大家指点,另外根据代码
输出的结果也不对, 不明白问题到底出在哪里?应该怎么修改下才能得到想要的结果,还请大家不吝赐教!!!谢谢!
代码如下:
[color=ff00ff]#!/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++;}
}
[color=red] foreach $RT_list (@RT)
{splice(@mass_retention_time, $RT_list, 1);} [/color]
}
$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);[/color]