Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2016-12-06 03:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (99 votes). Check out past polls.