Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
No such thing as a small change
 
PerlMonks  

Re: min and mindex

by rjt (Chaplain)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (14)
As of 2014-04-18 19:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls