Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

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


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 15: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
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found