Given your one-to-one mapping between the two arrays (i.e., the same number of elements) and the numbers in @array1 are not repeated, consider the following:

use strict; use warnings; use List::Util 'min'; my %hash; my @array1 = ( 5, 2, 3, 4, 1, 6, 7 ); my @array2 = ( "a", "b", "c", "d", "e", "f", "g" ); my %array1Hash = map { $array1[$_] => $_ } 0 .. $#array1; @hash{@array1} = @array2; my $array1Min = min @array1; print 'The minimum value in @array1 is ', $array1Min, ".\n"; print 'The position of ', $array1Min, ' in @array1 is ', $array1Hash{$array1Min}, ".\n"; print 'The element in @array2 at position ', $array1Min, ' is ', $hash{ min @array1 }, '.';

Output:

The minimum value in @array1 is 1. The position of 1 in @array1 is 4. The element in @array2 at position 1 is e.

Two hashes are created. The first (%array1Hash) pairs each element of @array1 with its position in the array. The second (%hash) pairs the elements of @array1 as the keys with the elements of @array2 as values. When you've found the minimum value in @array1, you can use it as the key to get the associated value from @array2.

Hope this helps!

Update: Added printing the min val of @array1 and that element's position in the array.


In reply to Re: min and mindex by Kenosis
in thread min and mindex by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.