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

Re: min and mindex

by rjt (Deacon)
on Nov 06, 2012 at 17:28 UTC ( #1002536=note: print w/ replies, xml ) Need Help??

in reply to min and mindex

#!/opt/local/bin/perl use strict; use warnings; use List::MoreUtils qw(firstidx minmax); my @array1 = qw(9 8 7 1 2 3 4 5 6 7); my @array2 = qw(i h g a b c d e f g); my $min = (minmax @array1)[0]; my $mindex = firstidx { $_ eq $min } @array1; print "min = $min, mindex = $mindex, array2[$mindex] = $array2[$mindex +]\n";

This does scan @array1 twice, but that will not be an issue for small arrays, and if you are using the XS version of List::MoreUtils, this implementation may still be faster than rolling your own min/mindex code.

Comment on Re: min and mindex
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2015-11-28 12:55 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (741 votes), past polls