In the following code, I have used array slices to extract the points which are then compared using the rising function. This should be a lot more flexible than the numerous variables and the cumbersome if statement.
#! /usr/bin/perl -w use strict; use warnings; my @index; my @a2; # Read the data while(<DATA>) { chomp; next unless $_; if(/(\S+)\s+(\S+)/){ push @index,$1; push @a2, $2; } } # Process the array for (my $i=0; $i < @a2 - 7; $i++) { if (rising(@a2[$i..$i+4]) && rising(reverse @a2[$i+4 .. $i+7])) { my $idx = $index[$i + 4]; my $peak = $a2[$i + 4]; print "peak at $idx,$peak\n"; } } sub rising { my $last = shift; foreach (@_) { return 0 unless ($_ >= $last); $last = $_; } return 1; } __DATA__ 0 0.006944444 1 0.008196721 2 0.009615385 3 0.011111111 4 0.0125 5 0.013513514 6 0.013888889 7 0.013513514 8 0.0125 9 0.011111111 10 0.009615385 11 0.008196721 12 0.006944444 13 0.005882353 14 0.005 15 0.004273504 16 0.003676471
In reply to Re: Accessing keys through values
by inman
in thread Accessing keys through values
by cybersmithuk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |