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" }

In reply to Re: Array or Hash problem! by spazm
in thread Array or Hash problem! by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.