shakehands has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: get the peak values with perl
by BrowserUk (Patriarch) on Aug 12, 2013 at 08:17 UTC
    ,in the array 1,2,3,4,2,3,5,6,3,2,4,1

    1. i want to get the peak values [4,6,4]

      Assuming the criteria is: "values where the values either side are lower", that's easy.

      Iterate from 1 .. $#array -1; if $array[ $_ -1 ] < $array[ $_ ] and $array[ $_ +1 ] < $array[ $_ ] print $array[ $_ ];

      See for, if & print.

    2. i also wanna get [4,5,6,4]

      By what criteria do you select the pair (5,6) for inclusion whilst excluding the pair (3,4)?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: get the peak values with perl
by 2teez (Vicar) on Aug 12, 2013 at 07:05 UTC

    Hi shakehands,
    i am new perl use
    Welcome to the World... :).
    i want to get... No problems, you will need to show us what you have done. Please read How do I post a question effectively?.
    Apparently, from your request what you wanted from the array is:

    1. You want to get values that are divisible by 2, but greater than 2 itself
    2. All the numbers greater than 3.
    So, the question is how would you do that?
    Hope this helps

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re: get the peak values with perl
by ww (Archbishop) on Aug 12, 2013 at 18:51 UTC
    Your question is vague because your criteria are undefined.

    Why do the values "4,6,4" satisfy your definition of peak values? IOW, what does the phrase "peak values" mean -- without any ambiguity.
    Why in your second question (2), why do "4,5,6,4" satisfy your requirement?

    And not just BTW, not that my reference is to "your requirement." That's quite precise. It's your reqequirement, not ours, and you'll have to define your terms so we have something better than guesswork to work with in our attempts to help (which attempts are never our requirement, but which are done in keeping with the spirit of the Monastery -- to help you learn.