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

Re: index of the minimum element of the array

by ikegami (Pope)
on Jan 17, 2014 at 18:14 UTC ( #1070997=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use List::Util qw( reduce );
    
    ...
       my ($ar) = @_;
       return reduce { $ar->[$b] > $ar->[$a] ? $b : $a } 0..$#$ar;
    }
    
  2. or download this
    sub min_idx {
       my ($ar) = @_;
    ...
       for (1..$#$ar) { $idx = $_ if $arr->[$_] > $arr->[$idx]; }
       return $idx;
    }
    
  3. or download this
    my $min_idx = min_index(\@a);
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1070997]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2014-09-20 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (157 votes), past polls