Some comments on your code (not a direct answer, but seriously some things you should be carefull with (if you want an answer to your loop-question then look at the previous posts, BrowserUk's one is a good one)

First: $hash{$b[$x][1]} = \@{$b[$x]}; What are you tring to accomplish with the code? you are dereferencing an array-reference only to take the reference to it... It would be a lot easier to write: $hash{$b[$x][1]} = $b[$x]; which behaves exactly the same (or atleast when it really is an array-reference, if it isn't one then your code will die at some point)

defined $hash{$a[$x][1]} it might be better to write: ref $hash{ $a[$x][1] } eq 'ARRAY' this will make sure it is an array-reference, and not for example a scalar, or a hash-reference.

push @c, \@{$hash{$_}}; same note as before, dereferencing an array only to take the reference to it does not make sense. The main reason why all answers are so different is because of that (as in, people aren't 100% sure why you do that, or atleast that's what I believe)

Some side notes:


In reply to Re: How do I rewrite this foreach() loop as a map{} ? by Animator
in thread How do I rewrite this foreach() loop as a map{} ? by northwind

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.