Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
We don't bite newbies here... much
 
PerlMonks  

Re: How to get 2nd highest value from an array?

by l.frankline (Hermit)
on Dec 13, 2005 at 22:59 UTC ( [id://516513]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to How to get 2nd highest value from an array?

Hi,

A simplest way u can try...

@arr = (1..10); print sort($arr[$#arr]-1);

Regards
Franklin

Don't put off till tomorrow, what you can do today.

Replies are listed 'Best First'.
Re^2: How to get 2nd highest value from an array?
by tweetiepooh (Hermit) on Dec 14, 2005 at 10:39 UTC
    Well the code above prints value-1 of the last element not the value of the next to last element. In an array of sequential numbers the result may be the same ie element 9 contains value 9.

    So the print statement becomes

    print sort($arr[$#arr-1]);
    ?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://516513]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.