in reply to Search Hash with array element Help!
- For every array element, - Extract the numeric component of the element. - If the hash contains a key matching the extracted component, - If the hash value is empty, - Print whatever - Else - Print whatever
Update: I was letting you do the work yourself, but since others have posted code,
for my $id (@array_code) { my ($num) = $id =~ /(\d+)/ or next; next if !exists($code_numbers{$num}); my $code = $code_numbers{$num} || 'IN'; print("$id $code\n"); }
Or if %code_numbers can contain a value of '0',
for my $id (@array_code) { my ($num) = $id =~ /(\d+)/ or next; next if !exists($code_numbers{$num}); my $code = $code_numbers{$num}; $code = 'IN' if !length($code); print("$id $code\n"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Search Hash with array element Help!
by snape (Pilgrim) on Mar 04, 2010 at 21:38 UTC | |
by ikegami (Patriarch) on Mar 04, 2010 at 22:45 UTC |