jcwren beat me to it, but I was proud I knew this so I'm leaving it up : P

use strict; my @a = qw(a b c d e f); my @n = qw(1 2 3 4 5 6); my %hash; @hash{@a} = @n; print "$hash{a} $hash{e}\n\n";
outputs:
jptxs:/home/jptxs $ perl -w 2arrayHash 1 5 jptxs:/home/jptxs $
basically @hash tells perl to treat the hash as an array which means feeding it keys creates a slice just like @array[5,8,12] might. this assumes that you have two arrays of the same length, though. are you sure you do?

Update: the ever wise and vigilent chromatic has reminded me that a slice is a list and not an array - meaning it functions like something which is returned in list context, not like a set of values stored in and array. you could set that list equal to an array to access it later, but that is not what happens automatically. So don't expect to take a slice like @array[4..7] or @hash{@a} and find the value neatly tucked away anywhere for your use unless you make my @array_from_slice = @hash{@a};

"sometimes when you make a request for the head you don't
want the big, fat body...don't you go snickering."
                                         -- Nathan Torkington UoP2K a.k.a gnat


In reply to Re: (jptxs) Perlish array to hash by jptxs
in thread Perlish array to hash by nop

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.