Your skill will accomplishwhat the force of many cannot PerlMonks

### Re^2: min and mindex

 on Nov 06, 2012 at 18:15 UTC ( #1002553=note: print w/replies, xml ) Need Help??

in reply to Re: min and mindex

I like this example. What would you do if the values in array1 were not unique?

Replies are listed 'Best First'.
Re^3: min and mindex
by Kenosis (Priest) on Nov 06, 2012 at 19:07 UTC

Perhaps something like the following:

```use strict;
use warnings;
use List::Util 'min';

my %array1Hash;
my @array1 = ( 5,   2,   1,   4,   1,   6,   7 );
my @array2 = ( "a", "b", "c", "d", "e", "f", "g" );

push @{ \$array1Hash{ \$array1[\$_] } }, \$_ for 0 .. \$#array1;
my %array2Hash = map { \$_ => \$array2[\$_] } 0 .. \$#array2;

my \$array1Min = min @array1;
my \$positions = join ', ', @{ \$array1Hash{\$array1Min} };
my \$elements  = join ', ', map \$array2Hash{\$_}, @{ \$array1Hash{\$array1
+Min} };

print 'The minimum value in @array1 is ', "\$array1Min.\n";

print 'The position(s) of ', \$array1Min, ' in @array1: ', "\$positions.
+\n";

print 'The element(s) in @array2 at position(s) ', "\$positions: \$eleme
+nts.";

Output:

```The minimum value in @array1 is 1.
The position(s) of 1 in @array1: 2, 4.
The element(s) in @array2 at position(s) 2, 4: c, e.

Create A New User
Node Status?
node history
Node Type: note [id://1002553]
help
Chatterbox?
 [MidLifeXis]: hahaha: Just received a buzz-word-bingo- compliant email (internal) that starts with "%Firstname% %Lastname%...". It only gets better from there. choroba finds working in a small company boring comparing to a large corporation [MidLifeXis]: At least test before mass distribution. [MidLifeXis]: More opportunities for anonymous snafus :-) [MidLifeXis]: In a small group / company, at least you know who needs to buy the next round of beer for their mess-up. [MidLifeXis]: :-) [Discipulus]: are sure you are not really named "%Firstname% %Lastname%..." ? have you check your identity card?

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2017-01-19 12:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Do you watch meteor showers?

Results (170 votes). Check out past polls.