Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: min and mindex

by jwkrahn (Monsignor)
on Nov 07, 2012 at 05:11 UTC ( #1002626=note: print w/replies, xml ) Need Help??


in reply to min and mindex

I'm try to get the min value and position in array1.

You could use a simple loop:

$ perl -le' my @array1 = (1,2,3,4,5,6,7); my @array2 = ("a","b","c","d","e","f","g"); my ( $min, $min_index ) = ( $array1[ 0 ], 0 ); for my $index ( 1 .. $#array1 ) { if ( $array1[ $index ] < $min ) { ( $min, $min_index ) = ( $array1[ $index ], $index ); } } print $min; print $min_index; ' 1 0

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002626]
help
Chatterbox?
[Corion]: A good morning!

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2017-10-20 06:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (259 votes). Check out past polls.

    Notices?