,in the array 1,2,3,4,2,3,5,6,3,2,4,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.
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.
| [reply] [d/l] [select] |
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:
- You want to get values that are divisible by 2, but greater than 2 itself
- 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
| [reply] |
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.
| [reply] [d/l] [select] |