You never actually use the hash that you create. You populate and work with the arrays @index and @a2.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.