Not completely sure I understood the question, and the sample code does a lot stuff that it's hard to figure out the purpose of. Ignoring the code, and just looking at your question, I think you can do (untested):

my %out_hash = (); @out_hash{@in_array, keys %in_hash} = (("0") x @in_array, values %in_h +ash);

BTW, a "normal array" is always just called an array. A "hash array" is usually called just a hash, but sometimes is called an associative array.

The aboove works using a "hash slice". This looks like @hash{LIST}, and results in a list (which can be assigned to) of the values in %hash for each key in LIST. It also uses the x operator to make a list of scalar(@in_array) "0"'s.

So the assignment will initially set $out_hash{key} to "0", for each key in @in_array, then set $out_hash{key} to $in_hash{key} for each key in %in_hash.

Update: the above is not likely to be useful to you. I misinterpreted your "match" to mean "eq", instead of a regex match. It would be helpful if you would annotate the sample code to show which parts do and which parts don't work as you expect. Would I be correct in guessing it is just the final if statement that doesn't do what you want? I suspect you meant !~, not != there, but even that won't do what you want. You have to loop over all the keys seeing if they do match.

Update: removed extra )


In reply to Re: normal array exists question by ysth
in thread normal array exists question 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.