http://www.perlmonks.org?node_id=826772


in reply to Array or Hash problem!

I think I understand your request, but I may have misunderstood the mapping of code, number and acc_id.

you have: @code_array ==> full code strings of the accounts.
you have: @code_array_no_letters => numeric version of code strings.
you have: a database keyed on numeric versions of the code strings mapping to an acc_id.
You want: a list of code => acc_id.

My advice is to always start with a picture (literal or figurative) of your data and your final output. This is very helpful when explaining to others and asking for help.

#!/usr/bin/perl use warnings; use strict; my @code_array = qw(7772344 2233421 TMW2222987 TMA2222333 TMW9999988 AMQ8873332 AMQ1111877); #prime a lookup from the numeric code back to the full code. my %code_by_num; for my $code (@code_array) { (my $num = $code) =~ s/\D//g; $code_by_num{ $num } = $code; } #... while (my $pt = $sth->fetchrow_hashref) { my $accountnumber = $pt->{'accounts'}; my $acc_id = $pt->{'id'}; my $accountcode = $code_by_num{ $accountnumber }; print "$accountcode $acc_id\n" }