Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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?
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 making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-09-01 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (16 votes), past polls