in reply to How do I rewrite this foreach() loop as a map{} ?
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:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do I rewrite this foreach() loop as a map{} ?
by northwind (Hermit) on May 10, 2005 at 17:39 UTC |