- 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"); }
In reply to Re: Search Hash with array element Help!
by ikegami
in thread Search Hash with array element Help!
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |