Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to look up each element of an array in a hash, if it is present I wish to extract the corresponding values and push into a new array. I was wondering why my snippet of code won't work?! Cheers.
foreach my $thing (@array) { foreach ((my $key, my $value) = each %hash) { if ($key == $thing) { push @new_array, $value; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: comparing array elements to hash keys
by Zaxo (Archbishop) on Jul 02, 2003 at 14:20 UTC | |
|
Re: comparing array elements to hash keys
by CukiMnstr (Deacon) on Jul 02, 2003 at 14:21 UTC | |
|
Re: comparing array elements to hash keys
by hardburn (Abbot) on Jul 02, 2003 at 14:24 UTC | |
|
Re: comparing array elements to hash keys
by davorg (Chancellor) on Jul 02, 2003 at 14:33 UTC | |
by dvergin (Monsignor) on Jul 03, 2003 at 19:53 UTC |