Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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


Comment on Re: min and mindex
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2014-12-22 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (130 votes), past polls