Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Answer: How can I find the index of the biggest element in an array?

by jdporter (Canon)
on Feb 18, 2013 at 14:39 UTC ( #1019348=categorized answer: print w/replies, xml ) Need Help??

Q&A > arrays > How can I find the index of the biggest element in an array? - Answer contributed by jdporter

A recursive solution.

sub _index_of_largest { my $X = shift; my $L = shift; my $x = $#_; my $l = pop; defined $X and $L > $l and ($x,$l) = ($X,$L); @_ or return $x; unshift @_, $x, $l; goto &_index_of_largest } sub index_of_largest { @_ or die; _index_of_largest(undef,undef,@_); } my $i = index_of_largest( @a );

  • Comment on Answer: How can I find the index of the biggest element in an array?
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[erix]: (sorry, I'm always a bit violent on fridays)
LanX predicts problems for Erix next time he lines up at an US immigration counter
[erix]: but tuesdays just as bad
[erix]: thanks for the heads-up but that's a line-up studiiously avoided :P
[LanX]: yeah too far for someone who can't even make it to Amsterdam
LanX looking for a good magit tutorial
LanX ... and git in general
[erix]: I've been to Amsterdam before you were born
[LanX]: 1899?

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2017-08-18 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (302 votes). Check out past polls.

    Notices?