while(){ if($cnt % $nr_samples == 0){ $lower_bound = $lower_bound+$nr_samples; $upper_bound = $upper_bound+$nr_samples; } $cnt++; last if $upper_bound > ($length-1); foreach my $station(@stations){ open OUT, ">$span.$station.alpha.sac.data"; print OUT "2 $nr_samples\n"; for my $seeking($lower_bound..$upper_bound){ my $eval_file_2 = $suffix ? sprintf"%s%s_%s_%s",$prefix,$suffix,$station,$span : sprintf"%s_%s_%s",$prefix,$station,$span; open(FILE, "< $eval_file_2") or die "Can't open $eval_file_2 for reading: $!\n"; open(INDEX, "+>$eval_file_2.idx") or die "Can't open $eval_file_2.idx for read/write: $!\n"; build_index(*FILE, *INDEX); my $line = line_with_index(*FILE, *INDEX, $seeking); close FILE; close INDEX; chomp $line; my($time,$value)=split(/\s+/,$line); printf OUT "%.3f %.10f\n",$time,$value; } close OUT; } }